Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I need to find the city and state from a zip code. Does anyone know a good plugin/API that I can use to do this?
gem install geokit
In IRB:
require 'geokit'
geo = GeoKit::Geocoders::MultiGeocoder.multi_geocoder('90210')
if geo.success
geo.state # => CA
geo.city # => Beverly Hills
end
A more lightweight option is the Area gem.
require 'area'
'11211'.to_region #=> "Brooklyn, NY"
See Jason's answer. It works nicely.
The problem is that the USPS doesn't allow bulk downloads of their zip-code lists unless you pay for it. Google's API, which is used in the gem mentioned by Splashlin, no longer seems to support the city and state, instead it now returns the area code:
require 'open-uri'
require 'json'
json = JSON::parse(open('http://maps.google.com/maps/geo?q=852581').read)
puts json
# >> {"name"=>"852581", "Status"=>{"code"=>602, "request"=>"geocode"}}
This page shows some ways you could roll your own. The sources of the data might not be current though:
http://www.ruby-forum.com/topic/48815
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I'm writing a ruby script whose purpose is generating contracts. It is very simple to implement. I just load up a bunch of variables and input those into a big string all at once like so:
outputstring = <<-eos
#{Time.now.to_date.to_s}
...
eos
It has a bunch of other fancy words after the date, but I want the date to be something like: "January 1st, 2015". I could manually implement all of this noise, but I'm thinking there has got to be a gem that will quickly handle this task for me. I see gems like number_in_words and have to wonder..
Thanks
Does it have to be a gem?
What about this:
2.0.0-p247 :001 > Time.now.strftime("%B %-d, %Y")
=> "August 7, 2014"
and/or
2.0.0-p247 :002 > Time.parse("2015-01-01").to_date.strftime("%B %-d, %Y")
=> "January 1, 2015"
(you might have to require 'time' for the second example
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a Sublime Text plugin for Ruby that, after I type class/def something + Enter, will automatically insert end and place the curser in the class/method?
For example, typing def initialize(args) + Enter would result in:
def initialize(args)
#cursor here
end
In Textmate if you type def + Tab, it sets things up for you like that. I believe Sublime does the same.
I haven't used sublime, but here is what i found.
you could create snippets using Ruby on Rails Snippet package
You could use the solution given in 'How to automatically add "end" to code blocks?'.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Ruby 2.0 + rails 4.0
I want to show weather-feed on the public site, is there any gem which will show the weather according to the city name ?
without any registrations and charges.
Any suggestion ?
Why? write your using nokogiri and yahoo weather api!
it is quite a way try to do something myself and know more than using someone else's
For example:
require "nokogiri"
require "open-uri"
link = "http://weather.yahooapis.com/forecastrss?w=2123260&u=c" #2123260 this code of my city
data = Nokogiri::XML(open(link))
data.xpath("//item//yweather:condition")[0].to_s
#=> "<yweather:condition text=\"Cloudy\" code=\"26\" temp=\"-6\" date=\"Tue, 10 Dec 2013 3:30 pm MSK\"/>"
And more pictures available weather schedule for the week and so on. Just take it!
That's all
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
How can I retrieve data from OpenStreetMap (OSM) using the OSM API (http://wiki.openstreetmap.org/wiki/API) and Ruby? Is there any ruby gem available which serves my purpose? I have been searching for a good solution for my purpose but nothing served me exactly what I need.
As for example : Given the country name as input, I need to get the list of all streets of that country etc.
Any kind of link/code sample or starting point is fine. I can then explore more to find out what I need exactly. Thanks!
As the question as posed is off topic for Stack Overflow, I will answer the question of "How to find something I can use" rather than give any kind of recommendation on a tool itself.
I am not familiar with any gems for OpenStreetMap.
So I do this command from the terminal:
gem list --remote | grep street
And my terminal answers me with this:
openstreetmap (0.2.1)
And then I pull up my trusty browser, and open up ruby-toolbox.org and search for openstreetmap.
This produces a page that shows 30 results. In there, I see the mentioned gem, but also I see Rosemary which seems promising, as it is an "OpenStreetMap API client for ruby" and it was last updated only 4 months ago.
So, hopefully this helps in future searches. You have a lot of tools available to get started on your search to get to the point you are asking for in this question, so that you can get down to the business of doing what you need.
The main API you want to use is not suitable for such queries. It is mainly for editing and retrieving small amounts of map data within a small region. For larger queries better use the Overpass API which is much faster and also allows very complex query conditions if needed.
The Overpass API uses XML as input and serves either XML or JSON as output format. So it should be rather easy to use in any common scripting language.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
What frameworks exist to add AOP to Ruby?
With Ruby 2.0+, you don't necessarily need a framework:
module BarkLogger
def bark
puts "Logging ##name's bark!"
super
end
end
class Dog
prepend BarkLogger
def initialize(name)
#name = name
end
def bark
puts "##name the dog says bark!"
end
end
Dog.new("Rufus").bark
Output:
Logging Rufus's bark!
Rufus the dog says bark!
You haven't specified any criteria for evaluating different frameworks, so here's one that I found after 3 seconds on Google: Aquarium.
Another one, suggested by #Telemachus: gazer.
Shameless plug: aspector could be what you are looking for. It allows you to define aspect and then apply to one or more targets.
I tried 2 or 3 years ago Aquarium gem at university project. Worked nice, aim of project was comparing with AspectJ, to find out if it is capable of all things as AspectJ. At that time a lot of functionality, which AspectJ was capable of, was missing. But now I see a many things were added, so it's worth a try again.
AspectR (last release looks like in 2002) - originally the canonical AOP library in Ruby.
Facets - has some AOP functionality.