Module: MilkCap::RTM::DataNormalization
- Included in:
- Task
- Defined in:
- lib/milk_cap/rtm/data_normalization.rb
Overview
Helper methods to normalize incoming data
Instance Method Summary collapse
-
#normalize_rtm_tags_hash(tags_hash) ⇒ Object
Normalize data values returned in RTM’s json ‘tags’ keys to an Array of strings.
-
#normalize_tags_array(tags) ⇒ Object
Converts various forms of tag lists into an Array of strings.
Instance Method Details
#normalize_rtm_tags_hash(tags_hash) ⇒ Object
Normalize data values returned in RTM’s json ‘tags’ keys to an Array of strings.
RTM returns the value for it’s ‘tags’ key in a few formats:
When there are no tags, an empty JSON array: []
When there is one tag, a hash with “tag” key, set to a string for the tagname: { “tag”: “tagname” }
When there are multiple tags, a hash with “tag” key, set to a JSON array of strings: { “tag”: [“tagname1”, “tagname2”] }
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/milk_cap/rtm/data_normalization.rb', line 31 def () if .is_a?(Array) else if ['tag'].is_a?(Array) ['tag'] else [['tag']] end end end |
#normalize_tags_array(tags) ⇒ Object
Converts various forms of tag lists into an Array of strings.
tags
can be nil, a string of one or more comma separated tags, or an array. Returns an array of stripped strings.
10 11 12 13 14 15 16 17 |
# File 'lib/milk_cap/rtm/data_normalization.rb', line 10 def () return [] if .nil? if .kind_of? String = .split(",") end return .map { |i| i.strip } end |