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 |
# File 'lib/ext/hash.rb', line 21 def find_by(val, attr = 'id') each_value do |p| return p if p[attr].to_s == val.to_s 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 = [] 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 = [] each do |key, value| res << ":#{key} => \"#{value.to_s.gsub('"', '\"')}\"" end res.join ',' end |
#to_sym ⇒ Object
28 29 30 |
# File 'lib/ext/hash.rb', line 28 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<!–:–>
66 67 68 69 70 71 72 |
# File 'lib/ext/translator.rb', line 66 def to_translate res = [] each do |key, val| res << "<!--:#{key}-->#{val}<!--:-->" end res.join('') end |