Module: Stem::Util
- Defined in:
- lib/stem/util.rb
Instance Method Summary collapse
- #get_filter_opts(filters) ⇒ Object
- #swirl ⇒ Object
- #tags_to_filter(tags) ⇒ Object
- #tagset_to_hash(tagset) ⇒ Object
Instance Method Details
#get_filter_opts(filters) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/stem/util.rb', line 35 def get_filter_opts(filters) opts = {} filters.keys.sort.each_with_index do |k, n| v = filters[k] opts["Filter.#{n}.Name"] = k.to_s v = [ v ] unless v.is_a? Array v.each_with_index do |v, i| opts["Filter.#{n}.Value.#{i}"] = v.to_s end end opts end |
#swirl ⇒ Object
3 4 5 |
# File 'lib/stem/util.rb', line 3 def swirl @swirl ||= Swirl::AWS.new :ec2, load_config end |
#tags_to_filter(tags) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stem/util.rb', line 19 def () if .is_a? Hash = .inject({}) do |h, (k, v)| # this is really awful. how can i make this non-awful? k = "tag:#{k}" unless k.to_s == "architecture" h[k.to_s] = v h end get_filter_opts() elsif .is_a? Array get_filter_opts( { "tag-key" => .map(&:to_s) }) else get_filter_opts( { "tag-key" => [.to_s] }) end end |
#tagset_to_hash(tagset) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/stem/util.rb', line 7 def () if .is_a?(Hash) {["item"]["key"] => ["item"]["value"]} else .inject({}) do |h,item| k, v = item["key"], item["value"] h[k] = v h end end end |