How can I find the content between multiple parameter strings (E.G. /contact-group/{ID}/member/{CONTACT-ID}) - ruby

I had searched around but couldn't find something for it specifically. I was looking for a way to find the content of a URL (In this case these are URIs in a rest API)
A few examples of these look like:
/currency/{currency-id}
Or
/contact-group/{ID}/member/{CONTACT-ID}
The parameters always can be different, however they always are between {}, in different forms within the string. I know how I can replace these when there is only one in the URI without issue, but at runtime the programmer won't know these, and I'm trying to prevent having to define them and because of this when URIs contain multiple parameters I'm not sure how to obtain each case of them.
Happy for any ideas on how to get around this!

Seems like you're looking for a basic example of routing:
# in config/routes.rb
get "/:param_1/:param_2", to: "MyController#some_action"
Then in the controller you'd be able to get params[:param_1] and such.
You can see Rails' routing guide for more info
Maybe I'm not totally understanding your question, though. If you're looking to be able to capture a variable number of params, there's a special syntax for passing arrays in the query param.
See this: Passing array of parameters through get in rails

The answer to this was here
Basically using parameterset = url.scan(/{.+?}/) (replace url with your string name), and what's in scan with your parameter list, I can use this to do
parameterset.each { |x| x.... etc}

Related

Can't figure out how to search LOINC using FHIR for a specific test by name?

Can anyone provide some insight on the required syntax to use to search LOINC using FHIR for a specific string in the labs descriptive text portion of an Observation resource?
Is this even possible?
The documentation is all over the place and I can't find an example for this generic kind of search.
I found similar examples here: https://www.hl7.org/fhir/2015Sep/valueset-operations.html
Such as: GET "[base]/ValueSet/23/$validate-code?system=http://loinc.org&code=1963-8&display=test"
But none of them are providing a general enough case to do a global search of the LOINC system for a specific string in an Observation resource.
None of my attempts to use the FHIR UI here, http://polaris.i3l.gatech.edu:8080/gt-fhir-webapp/search?serverId=gatechreadonly&resource=Observation , have been successful. I keep getting a 500 Internal Server Error because I don't know the correct syntax to use for the value part of the search, and I can't find any documentation out of all the copious documents online that explains this very simple concept.
Can anyone provide some insight?
Totally frustrated at this point.
Observation?code=12345-6
or
Observation?code=http://loinc.org|12345-6
where 12345-6 is whatever LOINC code you want to look for (e.g. 39802-4)
The second ensures you'll only match on LOINC codes as opposed to codes from other systems, though given the relatively unique format of LOINC codes, you're mostly safe without including that.
If you want to search for a set of codes, then you can separate the codes or the tuples with commas: E.g.
Observation?code=12345-6,12345-7
or
Observation?code=http://loinc.org|12345-6,http://loinc.org|123456
If you expect to search by a really long list of codes frequently, you can define a value set that includes all the desired codes and then filter by value set:
Observation?code:in=http://somwhere.org/whatever/ValueSet/123
Note: for readability, I haven't escaped the URL contents, but you'll need to escape the URL values appropriately.

How to get collections from sub-folder in docpad?

my folds structure are something like this:
documents
techs
docs
I want to get a collection from docs, my code is :
techs: ->
#getCollection("html").findAllLive({relativeOutDirPath: /techs/docs/},[{date: -1}]).on "add", (model) ->
model.setMetaDefaults({layout: "post"})
It just won't works... Could somebody tell me what's going on?
The /techs/docs/ in {relativeOutDirPath: /techs/docs/} is parsed as a regular expression, rather than a string. Wrap it in quotes so you have {relativeOutDirPath: "/techs/docs/"} instead. You may or may not need the initial slash, I can't remember.
You may want to use the convenient helper provided by Docpad : getFilesAtPath.
Maybe you should read the file "docpad.coffee"
There is a section "collection", you can set collection named "html", and select all files in (database).
I've had problems depending on what system I'm running node.js and docpad on (ie Windows) with file path conventions. So I resort to the following to make sure I'm not having any of those sort of problems:
#getCollection("html").findAllLive({relativeOutDirPath:path.join('techs','docs')},[date:-1])
Note the 'path.join' bit
Just as example, all html documents from path starts with "post"
#getCollection("html").findAllLive({relativeOutDirPath: {$beginsWith: 'post'}})

get the ASIN number from amazon URL

Given a amazon product URL, which can either be
http://amazon.com/gp/product/ASIN/*
http://amazon.com/*/dp/ASIN/*
http://amazon.com/dp/ASIN/*
how do i scrap the ASIN number from the URL in Ruby ? I am not good at writing regular expressions.
Use should find match by:
scan(/https?:\/\/(?:www\.|)amazon\.com\/(?:gp\/product|[^\/]+\/dp|dp)\/([^\/]+)/)
If you are going to do a lot of URL parsing, I'd recommend looking at the Addressable::URI gem. It will make it a lot easier to maintain than parsing URLs with regex. Take a look at its Template module too, which is designed just for this purpose.
Look at the examples on the main Addressable page for more information.
You could also use Ruby's built-in URI module, to get the path using path, along with a simple string split and some logic to look at which element has the "dp" and then take the next element in the array or "gp" and take the second following element.

howto get Builder to create <tag></tag> instead of <tag/>

I,m using Builder::XmlMarkup to create xml. I want to create a tag without content because the api force me to create this.
If I use a blog
xml.tag do
end
I get what i need
<tag></tag>
but I want it shorter
xml.mytag
this gives me
<mytag/>
but i want
<mytag></mytag>
what do I have to pass as option.
regards Kai
Just pass empty string as a parameter. xml.mytag('')
Why do you want <mytag></mytag> instead of <mytag/>? Since the output is XML, downstream applications should not know or care about the difference.
According to the Infoset spec (Appendix D point 7), "The difference between the two forms of an empty element: <foo/> and <foo></foo>" is not represented in the XML Information Set.
This doesn't answer your "how" question, but if you discover that you actually don't need to do what you're trying to do, it may save you from a difficult and unnecessary wild goose chase.
ok empty string is nice, another one-line-way is empty block I found out.
xml.mytag{}

In MVC, should pagination info go in the path or querystring?

In the path:
Format: http://mydomain.com/{category}/{subcategory}/{pageNumber}/{pageSize}
Example: http://mydomain.com/books/thriller/3/25
In the querystring:
Format: http://mydomain.com/{category}/{subcategory}? pageNumber={pageNumber}&pageSize={pageSize}
Example: http://mydomain.com/books/thriller?pageNumber=3&pageSize=25
I like having everything on the path, but my problem with that is that while it is obvious (or at least somewhat obvious) what "books" and "thriller" are in first example, the "3" and "25" seem pretty arbitrary by contrast.
Is there a canonical method for determining what goes where in MVC, or is it really just up to the dev?
I prefer things like pagenumbers to be in the querystring variables. I think there's a difference in descriptiveness between
http://mydomain.com/books/thriller?pagesize=50&page=4
and
http://mydomain.com/books/thriller/50/4
The point (to me) of having clean url's is for them to be more descriptive and readable, and I find the first example to be just that.
One interesting point made byJohnRudolfLewis is:
One rule of thumb that I follow is
that if the argument is required,
consider using the path, if the
argument is optional, always use
querystring arguments.
One rule of thumb that I follow is that if the argument is required, consider using the path, if the argument is optional, always use querystring arguments.
Overall, I'd stick to whatever makes the url look more readable.
This site puts it in the querystring: https://stackoverflow.com/questions?page=2&pagesize=30
Well, it's obviously up to you. But, you're designing a RESTful interface that's supposed to be human readable. The querystring is much better in that regard. Otherwise you're looking at two numbers that could really be anything. And who's going to remember the order?
Is there a canonical method for determining what goes where in MVC, or is it really just up to the dev?
It's up to you.
MVC is about the organization/flow of your server-side code and seperating the view from the business layer, not so much about query parameters.
You could also consider the following
Format
http://mydomain.com/{category}/{subcategory}/page/{pageNumber}/results/{pageSize}
Example
http://mydomain.com/books/thriller/page/3/results/25
It is pretty much up to the dev. I would say put the pageSize in the URL.

Resources