class MetofficeDatapoint::Mash
Public: Provides pseudo-objects (a Hashie::Mash) representing the responses from the Met Office DataPoint API.
Warning: The conversion process is slow for large objects. It is not recommended to use this class on responses
from requests to the API returning data for all locations.
Protected Instance Methods
convert_key(key)
click to toggle source
Protected: Convert keys to a more rubyesque style (underscroce, lowercase). Excludes keys with specific meanings. Overloads the the convert_key
Mash
method.
key - String, possibly containing CamelCase words and/or dash-es
Examples:
convert_key("CamelCase") => camel_case convert_key("dash-es") => dash_es
Returns String based on lowercase letters and an underscore for separation.
# File lib/metoffice_datapoint/mash.rb, line 22 def convert_key(key) case key when '$' 'text' when 'D', 'Dm', 'F', 'FDm', 'FNm', 'G', 'Gm', 'Gn', 'H', 'Hm', 'Hn', 'Nm', 'P', 'Pp', 'PPd', 'PPn', 'S', 'T', 'U', 'V', 'W' key else key.to_s.strip. gsub('@', ''). gsub(' ', '_'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). squeeze("_"). downcase end end