Class: Hash
- Defined in:
- lib/open_classes/hash/table.rb,
lib/open_classes/hash/gte_gte.rb,
lib/open_classes/hash/html_table.rb
Overview
Hash
Instance Method Summary collapse
-
#>>(dummy = nil) ⇒ Object
return HashContext for each execute.
-
#html_table ⇒ Object
get html table string from key + value.
-
#table ⇒ Object
get pipe format table string from key + value.
Instance Method Details
#>>(dummy = nil) ⇒ Object
return HashContext for each execute
Example
h = {key1: "value1", key2: "value2"}
h.>>.upcase # => {key1: "VALUE1", key2: "VALUE2"}
h.>>.+('_hoge') # => {key1: "value1_hoge", key2: "value2_hoge"}
42 43 44 |
# File 'lib/open_classes/hash/gte_gte.rb', line 42 def >>(dummy = nil) HashContext.new(self) end |
#html_table ⇒ Object
get html table string from key + value
Examples
valid commma case
{
:key_1 => :value1,
:key__2 => :value2,
:key___3 => :value3,
}.html_table
result
<table>
<tr>
<td>key_1</td>
<td>value1</td>
</tr>
<tr>
<td>key__2</td>
<td>value2</td>
</tr>
<tr>
<td>key___3</td>
<td>value3</td>
</tr>
</table>
34 35 36 37 38 39 40 |
# File 'lib/open_classes/hash/html_table.rb', line 34 def html_table ret = [keys, values].treduce(['<table>']) do |ret, one, other| ret << " <tr>\n <td>#{one}</td>\n <td>#{other}</td>\n </tr>" ret end ret.join("\n") + "\n</table>\n" end |
#table ⇒ Object
get pipe format table string from key + value
Examples
valid commma case
{
:key_1 => :value1___________________,
:key__2 => :value2,
:key___3 => :value3,
}.table
result
|key_1 |value1___________________|
|key__2 |value2 |
|key___3|value3 |
23 24 25 26 27 28 29 30 |
# File 'lib/open_classes/hash/table.rb', line 23 def table ret = [keys, values].treduce([]) do |ret, one, other| ret << "|#{one}|#{other}|" ret end ret = ret.join("\n") + "\n" ret.justify_table end |