Class: Unpatched::NormalWrapper

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/unpatched.rb

Instance Method Summary collapse

Methods inherited from Wrapper

#and, const_missing, #initialize, #inspect

Constructor Details

This class inherits a constructor from Unpatched::Wrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object (private)



137
138
139
140
141
142
143
144
145
# File 'lib/unpatched.rb', line 137

def method_missing(m, *a, &b)
  a.map! { |e| Utils.unwrapped e }
  if m[-1] == ?! and NormalWrapper.method_defined?(method = m[0..-2])
    result = __send__(method, *a, &b)
    Utils.unwrapped result
  else
    Utils.wrapped @value.__send__(m, *a, &b)
  end
end

Instance Method Details

#after(other) ⇒ Object



116
117
118
# File 'lib/unpatched.rb', line 116

def after(other)
  Utils.wrapped Utils.unwrapped(other) + @value
end

#agoObject



120
121
122
# File 'lib/unpatched.rb', line 120

def ago
  before Time.now
end

#before(other) ⇒ Object



112
113
114
# File 'lib/unpatched.rb', line 112

def before(other)
  Utils.wrapped Utils.unwrapped(other) - @value
end

#dayObject Also known as: days



108
# File 'lib/unpatched.rb', line 108

def day;     Utils.wrapped Utils.num(@value) * DAY    end

#from_nowObject



125
126
127
# File 'lib/unpatched.rb', line 125

def from_now
  after Time.now
end

#hourObject Also known as: hours



107
# File 'lib/unpatched.rb', line 107

def hour;    Utils.wrapped Utils.num(@value) * HOUR   end

#minuteObject Also known as: minutes



106
# File 'lib/unpatched.rb', line 106

def minute;  Utils.wrapped Utils.num(@value) * MINUTE end

#monthObject Also known as: months



109
# File 'lib/unpatched.rb', line 109

def month;   Utils.wrapped Utils.num(@value) * MONTH  end

#secondObject



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/unpatched.rb', line 84

def second
  value = Utils.unwrapped @value
  if value.respond_to? :second
    value.second
  else
    Utils.wrapped Utils.num(value)
  end
rescue TypeError, ArgumentError => err
  raise err unless value.respond_to? :[]
  value[1]
end

#secondsObject



105
# File 'lib/unpatched.rb', line 105

def seconds; Utils.wrapped Utils.num(@value)          end

#underscoreObject



96
97
98
99
100
101
102
103
# File 'lib/unpatched.rb', line 96

def underscore
  to_s.
    gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

#yearObject Also known as: years



110
# File 'lib/unpatched.rb', line 110

def year;    Utils.wrapped Utils.num(@value) * YEAR   end