Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ext/hash.rb,
lib/ext/translator.rb
Instance Method Summary collapse
-
#find_by(val, attr = "id") ⇒ Object
used for hash of objects.
-
#to_attr_format(split = " ") ⇒ Object
convert hash to string like class=“class val” name=‘name val’.
-
#to_attr_url_format ⇒ Object
convert hash to attributes for url_path.
- #to_sym ⇒ Object
-
#to_translate ⇒ Object
convert hash to translation string structure sample: “hola mundo”, en: “Hello World” ==> <!–:es–>Hola Mundo<!–:–><!–:en–>Hello World<!–:–>.
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_format ⇒ Object
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_sym ⇒ Object
30 31 32 |
# File 'lib/ext/hash.rb', line 30 def to_sym symbolize(self) end |
#to_translate ⇒ Object
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 |