Module: RightSignature::Helpers::TagsHelper
- Defined in:
- lib/rightsignature/helpers/normalizing.rb
Overview
:nodoc:
Class Method Summary collapse
- .array_and_metadata_to_string_array(array_of_tags, hash_of_metadata) ⇒ Object
- .array_to_xml_hash(tags_array) ⇒ Object
- .metadata_hash_from_tags_string(tags_string) ⇒ Object
- .mixed_array_to_string_array(array_of_tags) ⇒ Object
- .tags_array_from_tags_string(tags_string) ⇒ Object
Class Method Details
.array_and_metadata_to_string_array(array_of_tags, hash_of_metadata) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rightsignature/helpers/normalizing.rb', line 4 def (, ) ||= [] ||= {} if !(.is_a?(Array) && .is_a?(Hash)) return raise ArgumentError, "Objects must be an array and a hash" end = .collect{|t| CGI.escape(t)} + .collect{ |k,v| "#{CGI.escape(k.to_s)}:#{CGI.escape(v.to_s)}" if ! v.to_s.strip.empty? }.select{ |t| ! t.to_s.strip.empty? } .join ',' end |
.array_to_xml_hash(tags_array) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rightsignature/helpers/normalizing.rb', line 68 def array_to_xml_hash() .map do |t| if t.is_a? Hash name, value = t.first {:tag => {:name => name.to_s, :value => value.to_s}} else {:tag => {:name => t.to_s}} end end end |
.metadata_hash_from_tags_string(tags_string) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rightsignature/helpers/normalizing.rb', line 34 def ||= "" if ! .is_a? String return raise ArgumentError, "Object must be a string" end Hash[ .split(',') .select{ |t| t =~ /:/} .collect{ |t| md = t.split(':') [CGI.unescape(md[0]), CGI.unescape(md[1])] } ] end |
.mixed_array_to_string_array(array_of_tags) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rightsignature/helpers/normalizing.rb', line 51 def mixed_array_to_string_array() return unless .is_a?(Array) = [] .each_with_index do |tag, idx| if tag.is_a? Hash << tag.collect{|k,v| "#{CGI.escape(k.to_s)}:#{CGI.escape(v.to_s)}"} elsif tag.is_a? String << CGI.escape(tag.to_s) else raise "Tags should be an array of Strings ('tag_name') or Hashes ({'tag_name' => 'value'})" end end .join(',') end |
.tags_array_from_tags_string(tags_string) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rightsignature/helpers/normalizing.rb', line 22 def ||= "" if ! .is_a? String return raise ArgumentError, "Object must be a string" end .split(',') .select{|t| t !~ /:/} .collect{|t| CGI.unescape(t)} end |