Module: MultiForecast::ConversionRule
- Included in:
- Client
- Defined in:
- lib/multiforecast/conversion_rule.rb
Instance Method Summary collapse
- #graph_name(path) ⇒ Object
- #id(path) ⇒ Object
- #ids(path) ⇒ Object
- #lstrip(string, substring) ⇒ Object
- #path(service_name, section_name, graph_name) ⇒ Object
- #section_name(path) ⇒ Object
- #service_name(path) ⇒ Object
- #uri_escape(string) ⇒ Object
- #uri_unescape(string) ⇒ Object
Instance Method Details
#graph_name(path) ⇒ Object
32 33 34 35 |
# File 'lib/multiforecast/conversion_rule.rb', line 32 def graph_name(path) path = lstrip(path, '/') File.basename(path) end |
#id(path) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/multiforecast/conversion_rule.rb', line 44 def id(path) path = lstrip(path, '/') @mapping.each do |base_path, base_uri| return base_path if path.index(base_path) == 0 end return @mapping.keys.first end |
#ids(path) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/multiforecast/conversion_rule.rb', line 52 def ids(path) path = lstrip(path, '/') @mapping.map do |base_path, base_uri| base_path if path.index(base_path) == 0 end.compact end |
#lstrip(string, substring) ⇒ Object
16 17 18 |
# File 'lib/multiforecast/conversion_rule.rb', line 16 def lstrip(string, substring) string.index(substring) == 0 ? string[substring.size..-1] : string end |
#path(service_name, section_name, graph_name) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/multiforecast/conversion_rule.rb', line 37 def path(service_name, section_name, graph_name) return "#{service_name}/#{section_name}/#{graph_name}" unless service_name == "multiforecast" dirname = uri_unescape(section_name) basename = graph_name dirname == "." ? basename : "#{dirname}/#{basename}" end |
#section_name(path) ⇒ Object
26 27 28 29 30 |
# File 'lib/multiforecast/conversion_rule.rb', line 26 def section_name(path) path = lstrip(path, '/') return path.split('/')[1] if path.count('/') == 2 uri_escape(File.dirname(path)) end |
#service_name(path) ⇒ Object
20 21 22 23 24 |
# File 'lib/multiforecast/conversion_rule.rb', line 20 def service_name(path) path = lstrip(path, '/') return path.split('/')[0] if path.count('/') == 2 'multiforecast' end |
#uri_escape(string) ⇒ Object
6 7 8 9 10 |
# File 'lib/multiforecast/conversion_rule.rb', line 6 def uri_escape(string) # + => '%20' is to avoid GF (Kossy?) bug # . => '%2E' because a/./b is recognized as a/b as URL CGI.escape(string).gsub('+', '%20').gsub('.', '%2E') if string end |
#uri_unescape(string) ⇒ Object
12 13 14 |
# File 'lib/multiforecast/conversion_rule.rb', line 12 def uri_unescape(string) CGI.unescape(string) if string end |