Module: Tweetwine::Support::Helper

Defined in:
lib/tweetwine/support.rb

Class Method Summary collapse

Class Method Details

.indexes_of_filled_matches(match_data) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/tweetwine/support.rb', line 115

def indexes_of_filled_matches(match_data)
  if match_data.size > 1
    (1...match_data.size).to_a.reject { |i| match_data[i].nil? }
  else
    [0]
  end
end

.pluralize_unit(value, unit) ⇒ Object



108
109
110
111
112
113
# File 'lib/tweetwine/support.rb', line 108

def pluralize_unit(value, unit)
  if %w{hour day}.include?(unit) && value > 1
    unit = unit + 's'
  end
  unit
end

.recursive_copy_hash(hash, &pair_modifier) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/tweetwine/support.rb', line 98

def recursive_copy_hash(hash, &pair_modifier)
  hash.inject({}) do |result, pair|
    value = pair.last
    value = recursive_copy_hash(value, &pair_modifier) if value.is_a? Hash
    key, value = pair_modifier.call(pair.first, value)
    result[key] = value
    result
  end
end