Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/roart/core/hash.rb

Instance Method Summary collapse

Instance Method Details

#to_content_formatObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/roart/core/hash.rb', line 2

def to_content_format
  fields = []

  self.each do |key, values|
    next if values.nil?

    key_name = 
      if key.to_s.match(/^cf_.+/)
        "CF-#{key.to_s[3..key.to_s.length].gsub(/_/, " ").camelize.humanize}"
      elsif key.to_s.match(/^CF-.+/)
        key.to_s
      elsif key.to_s.match(/^[a|A]ttachments/)
        nil
      else
        key.to_s.camelize
      end

    next if key_name.nil?

    values = [values] unless values.is_a?(Array)
    values.each do |value|
      value = Roart::ContentFormatter.format_string(value.to_s)
      fields << "#{key_name}: #{value}"
    end
  end

  content = fields.compact.sort.join("\n")
end

#with_indifferent_accessObject



31
32
33
34
35
# File 'lib/roart/core/hash.rb', line 31

def with_indifferent_access
  hash = HashWithIndifferentAccess.new(self)
  hash.default = self.default
  hash
end