I am creating a test that can be expressed as a disjunction of assertions; when the first assertion fails, then it should look at the next. Particularly, an item will be equal to one of two things. Which one, I do not know.
My code looks something like this. It does not work but it might give you an idea of what I am trying to do.
asset_one = Cache.asset_one
asset_two = Cache.asset_two
assert_equal(asset_one.name, Pages.name) or
assert_equal(asset_two.name, Pages.name)
The Pages.name should match one of the targets. I don't know which one. If it doesn't match the first, then I want it to skip it and try to match the second.
Any help is as always much appreciated.
If you want to match any one of the object having the given name, you can use assert_includes
asset_one = Cache.asset_one
asset_two = Cache.asset_two
assert_includes([asset_one, asset_two].map(&:name), Pages.name)
This should solve your purpose.
Related
(It's been a while since I've been here.)
I've been using the first version of PHRets v1 for years, and understood it well enough to get by, but now I'm trying to understand the advantages of v2.6.2. I've got it all installed and the basics are working fine. My issues are pretty much with comprehending fine points of query syntax that goes into the rets=>Search() statement. (I'm much more familiar with SQL statements). Specifically, I'd like to have a query return a list of properties, EXCLUDING those which already have the status of "Sold".
Here's where I am stuck: If I start with this
`$results = $rets->Search('Property', 'A','*',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);`
That works well enough. BUT I'd like to fit in a filter like:
"LIST_15 != Sold", or "NOT LIST_15=Sold"...something like that. I don't get how to fit/type that into a PHRets Search().
I like PHRets but it is so hard to find well-organized/complete documentation about specific things like this. Thanks in advance.
As in my comment above I've figured out that the filter goes in the third argument position ('*', as in the original question). The tricky thing was having to find a specific "sold" code for each class of properties and placing it in that position like so: '(LIST_15=~B4ZIT1Y75TZ)', (notice the =~ combination of characters that means "does not equal" in this context). I've found the code strings for each of the property types (not clear WHY they would need to be unique for each type of property: "Sold" is Sold for any type, after all) but the correct code for a single-family residential property (type 'A' ...at least for the MLS in which I have to search is:
$results = $rets->Search('Property', 'A','(LIST_15=~B4ZIT1Y75TZ)',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);
(again, the code to go with LIST_15 will be different for the different types of properties.) I think there is a better answer that involves more naturalistic language, but this works and I guess I will have to be satisfied with it for now. I hope this is of some use to anyone else struggling with this stuff.
I have been struggling to return the count of courses from this XML file that contain "Cross-listed" as their description. The problem I encounter is because I am using for, it iterates and gives me "1 1" instead of "2". When I try using let instead I get 13 which means it counts all without condition even when I point return count($c["Cross-listed"]. What am I doing wrong and how can I fix it? Thanks in advance
for $c in doc("courses.xml")//Department/Course
where some $desc in $c/Description
satisfies contains($desc, "Cross-listed")
return count($c)
The problem I encounter is because I am using for
You are quite correct. You don't need to process items individually in order to count them.
You've made things much too difficult. You want
count(doc("courses.xml")//Department/Course[Description[contains(., "Cross-listed"]])
The key thing here is: you want a count, so call the count() function, and give it an argument which selects the set of things you want to include in the count.
I have a a number of routes that can be like :
possible routes:
- mac-book-retina-17-pid234-234
- hp-laptop-pid234-234
- vaoe-x12-pid234-234
and I want to match all to one action using the constraints in Ruby route file. Something like
get 'products/:product_info', to: 'products#type', constraints: { product_info: /[a-z]+-a-z]+-a-z]+-pid\d+-\d+/ }
The problem is that the /[a-z]+-/ can get repeated 1 time, 2 times and 3 times, and it makes it hard to get a consistent shared Regex for all the cases.
The only part that is constant in all routes is the last part: pid234-234 which refers to the product id and another sub_id.
I am thinking of something like: find all strings untill you each this part(pid), but I do not know how to do that.
I would say a good place to start is dynamic-segments
get 'products/:product_info', to: 'products#type', constraints: { product_info: /[A-Z]\d{5}/ }
I hope that this helps
Happy Hacking
I think I managed to find a possible solution for this:
(.*)pid\d+-\d+
this regex will match all the strings until it reaches the pid-12-12.
Given a filename, I would like to know if there is a ruby way to obtain the constant name for it.
e.g:
"lib/myproject/connect.rb" => MyProject::Connect
p.s: I know I can create a script for this.
EDIT: consider only the first one at the top.
You may wanna take a look at the implementation of Inflector#camelize in ActiveSupport, see: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize
As part of a chat app I'm writing, I need to use regular expressions to match asterisks and underscores in chat messages and turn them into <strong> and <em> tags. Since I'm terrible with regex, I'm really stuck here. Ideally, we would have it set up such that:
One to three words, but not more, can be marked for strong/em.
Patterns such as "un*believ*able" would be matched.
Only one or the other (strong OR em) work within one line.
The above parameters are in order of importance, with only #1 being utterly necessary - the others are just prettiness. The closest I came to anything that worked was:
text = text.sub(/\*([(0-9a-zA-Z).*])\*/,'<b>\1<\/b>')
text = text.sub(/_([(0-9a-zA-Z).*])_/,'<i>\1<\/i>')
But it obviously doesn't work with any of our params.
It's odd that there's not an example of something similar already out there, given the popularity of using asterisks for bold and whatnot. If there is, I couldn't find it outside of plugins/gems (which won't work for this instance, as I really only need it in in one place in my model). Any help would be appreciated.
This should help you finish what you are doing:
sub(/\*(.*)\*/,'<b>\1</b>')
sub(/_(.*)_/,'<i>\1</i>')
Firstly, your criteria are a little strange, but, okay...
It seems that a possible algorithm for this would be to find the number of matches in a message, count them to see if there are less than 4, and then try to perform one set of substitutions.
strong_regexp = /\*([^\*]*)\*/
em_regexp = /_([^_]*)_/
def process(input)
if input ~= strong_regexp && input.match(strong_regexp).size < 4
input.sub strong_regexp, "<b>\1<\b>"
elsif input ~= em_regexp && intput.match(em_regexp).size < 4
input.sub em_regexp, "<i>\1<\i>"
end
end
Your specifications aren't entirely clear, but if you understand this, you can tweak it yourself.