Class: SeisRuby::Data::Cmtsolution::Hypocenter

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/seis_ruby/data/cmtsolution.rb

Constant Summary collapse

FIELDS =
[
  # name,        column,    converter
  [:data_source, ( 0..3 ), :strip],
  [:year,        ( 4..8 ), :to_i ],
  [:month,       ( 9..11), :to_i ],
  [:day,         (12..14), :to_i ],
  [:hour,        (15..17), :to_i ],
  [:minute,      (18..20), :to_i ],
  [:second,      (21..26), :to_f ],
  [:latitude,    (27..35), :to_f ],
  [:longitude,   (36..45), :to_f ],
  [:depth,       (46..51), :to_f ],
  [:mb,          (52..55), :to_f ],
  [:ms,          (56..59), :to_f ],
  [:region_name, (60..-1), :strip],
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Hypocenter

Returns a new instance of Hypocenter.



50
51
52
53
54
55
56
# File 'lib/seis_ruby/data/cmtsolution.rb', line 50

def initialize(str)
  h = {}
  FIELDS.each{|name, column, converter|
    h[name] = str[column].__send__(converter)
  }
  super(h)
end

Instance Attribute Details

#tableObject

Returns the value of attribute table.



57
58
59
# File 'lib/seis_ruby/data/cmtsolution.rb', line 57

def table
  @table
end

Instance Method Details

#origin_timeObject

Origin time



60
61
62
63
64
65
66
67
68
# File 'lib/seis_ruby/data/cmtsolution.rb', line 60

def origin_time
  sec = self.second
  int_sec = sec.to_i
  decimal_sec = sec - int_sec
  micro_sec = (decimal_sec*(10**6)).round
  Time.gm(
       self.year, self.month, self.day,
       self.hour, self.minute, int_sec, micro_sec)
end