Module: AgentXmpp::StandardLibrary::ArrayPatches::InstanceMethods
- Defined in:
- lib/agent_xmpp/patches/array.rb
Overview
Instance Method Summary collapse
-
#smash ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….…..
-
#to_x_data(type = 'result') ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….…..
Instance Method Details
#smash ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….…..
32 33 34 |
# File 'lib/agent_xmpp/patches/array.rb', line 32 def smash self.flatten.compact end |
#to_x_data(type = 'result') ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….…..
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/agent_xmpp/patches/array.rb', line 10 def to_x_data(type = 'result') data = Xmpp::XData.new(type) if first.kind_of?(Hash) field_type = lambda{|v| v.kind_of?(Array) ? 'list-multi' : nil} reported = Xmpp::XDataReported.new first.each_key {|var| reported.add_field(var.to_s)} data << reported each do |fields| item = Xmpp::XDataItem.new fields.each{|var, val| item.add_field_with_value(var.to_s, [val].flatten.collect{|v| v.to_s}, field_type[val])} data << item end else field = Xmpp::XDataField.new field.values = map{|v| v.to_s} field.type ='list-multi' data << field end data end |