module AIXM::Refinements

Constants

UPTRANS_FILTER
UPTRANS_MAP

Public Instance Methods

decapture() click to toggle source
    # File lib/aixm/refinements.rb
144 def decapture
145   Regexp.new(to_s.gsub(/\(\?<\w+>|(?<![^\\]\\)\((?!\?)/, '(?:'))
146 end
indent(number) click to toggle source
    # File lib/aixm/refinements.rb
192 def indent(number)
193   whitespace = ' ' * number
194   gsub(/^/, whitespace)
195 end
inflect(*inflections) click to toggle source
    # File lib/aixm/refinements.rb
174 def inflect(*inflections)
175   inflections.inject(self) do |memo, inflection|
176     AIXM.config.inflector.send(inflection, memo)
177   end
178 end
lookup(key_or_value, fallback=omitted=true) click to toggle source
    # File lib/aixm/refinements.rb
114 def lookup(key_or_value, fallback=omitted=true)
115   self[key_or_value] ||
116     (key_or_value if has_value?(key_or_value)) ||
117     (omitted ? fail(KeyError, "key or value `#{key_or_value}' not found") : fallback)
118 end
then_if(condition, &block) click to toggle source
    # File lib/aixm/refinements.rb
131 def then_if(condition, &block)
132   condition ? self.then(&block) : self
133 end
to_class() click to toggle source
    # File lib/aixm/refinements.rb
158 def to_class
159   Object.const_get(self)
160 end
to_dd() click to toggle source
    # File lib/aixm/refinements.rb
221 def to_dd
222   if match = self.match(DMS_RE)
223     "#{match['sgn']}1".to_i * "#{:- if match['hem_sw']}1".to_i * (
224       match['deg'].to_f +
225       match['min'].to_f/60 +
226       match['sec'].tr(',', '.').to_f/3600
227     )
228   end
229 end
to_digest() click to toggle source
   # File lib/aixm/refinements.rb
28 def to_digest
29   ::Digest::SHA512.hexdigest(flatten.map(&:to_s).join('|'))[0, 8]
30 end
to_dms(padding=3) click to toggle source
   # File lib/aixm/refinements.rb
47 def to_dms(padding=3)
48   degrees = self.abs.floor
49   minutes = ((self.abs - degrees) * 60).floor
50   seconds = (self.abs - degrees - minutes.to_f / 60) * 3600
51   minutes, seconds = minutes + 1, 0 if seconds.round(2) == 60
52   degrees, minutes = degrees + 1, 0 if minutes == 60
53   %Q(%s%0#{padding}d°%02d'%05.2f") % [
54     ('-' if self.negative?),
55     self.abs.truncate,
56     minutes.abs.truncate,
57     seconds.abs
58   ]
59 end
to_rad() click to toggle source
   # File lib/aixm/refinements.rb
72 def to_rad
73   self * Math::PI / 180
74 end
to_time() click to toggle source
    # File lib/aixm/refinements.rb
242 def to_time
243   Time.parse(self)
244 end
trim() click to toggle source
   # File lib/aixm/refinements.rb
89 def trim
90   (self % 1).zero? ? self.to_i : self
91 end
uptrans() click to toggle source
    # File lib/aixm/refinements.rb
263 def uptrans
264   self.dup.tap do |string|
265     string.upcase!
266     string.gsub!(/(#{UPTRANS_MAP.keys.join('|')})/, UPTRANS_MAP)
267     string.unicode_normalize!(:nfd)
268     string.gsub!(UPTRANS_FILTER, '')
269   end
270 end