Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/hash.rb,
lib/ext/translator.rb

Instance Method Summary collapse

Instance Method Details

#find_by(val, attr = "id") ⇒ Object

used for hash of objects



21
22
23
24
25
26
27
28
# File 'lib/ext/hash.rb', line 21

def find_by(val, attr = "id")
  self.each do |key, p|
    if p[attr].to_s == val.to_s
      return p
    end
  end
  nil
end

#to_attr_format(split = " ") ⇒ Object

convert hash to string like class=“class val” name=‘name val’



3
4
5
6
7
8
9
# File 'lib/ext/hash.rb', line 3

def to_attr_format(split = " ")
  res = []
  self.each do |key, value|
    res << "#{key} = \"#{value.to_s.gsub('"', '\"')}\""
  end
  res.join(split)
end

#to_attr_url_formatObject

convert hash to attributes for url_path



12
13
14
15
16
17
18
# File 'lib/ext/hash.rb', line 12

def to_attr_url_format
  res = []
  self.each do |key, value|
    res << ":#{key} => \"#{value.to_s.gsub('"', '\"')}\""
  end
  res.join ","
end

#to_symObject



30
31
32
# File 'lib/ext/hash.rb', line 30

def to_sym
  symbolize(self)
end

#to_translateObject

convert hash to translation string structure sample: “hola mundo”, en: “Hello World”

> <!–:es–>Hola Mundo<!–:–><!–:en–>Hello World<!–:–>



67
68
69
70
71
72
73
# File 'lib/ext/translator.rb', line 67

def to_translate
  res = []
  self.each do|key, val|
    res << "<!--:#{key}-->#{val}<!--:-->"
  end
  res.join("")
end