Class: SeisRuby::Data::Sac

Inherits:
SeisRuby::Data show all
Defined in:
lib/seis_ruby/data/sac.rb

Overview

Defined Under Namespace

Modules: Ascii, Binary, Body, Head

Instance Attribute Summary collapse

Attributes inherited from SeisRuby::Data

#meta_data, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, type = :binary, meta_data = {}) ⇒ Sac

Returns a new instance of Sac.



34
35
36
37
38
# File 'lib/seis_ruby/data/sac.rb', line 34

def initialize(raw_data, type = :binary,  = {})
  @raw_data = raw_data
  @meta_data = 
  parse!(type)
end

Instance Attribute Details

#bodyObject

Wave



41
42
43
# File 'lib/seis_ruby/data/sac.rb', line 41

def body
  @body
end

#headObject

Header



40
41
42
# File 'lib/seis_ruby/data/sac.rb', line 40

def head
  @head
end

Class Method Details

.load(raw_data, type = :binary, meta_data = {}) ⇒ Object



16
17
18
# File 'lib/seis_ruby/data/sac.rb', line 16

def self.load(raw_data, type = :binary,  = {})
  new(raw_data, type, )
end

.load_file(file) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/seis_ruby/data/sac.rb', line 8

def self.load_file(file)
  raw_data = File.read_uri(file)
  type = type_from_file(file)
   = {file: file}

  load(raw_data, type, )
end

.type_from_file(file) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/seis_ruby/data/sac.rb', line 20

def self.type_from_file(file)
  if ::SeisRuby::Data::Sac::Binary.uri_for_self?(file)
    :binary
  elsif ::SeisRuby::Data::Sac::Ascii.uri_for_self?(file)
    :ascii
  else
    raise ArgumentError, "Unsupported extension: #{ext}"
  end
end

.uri_for_self?(uri) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/seis_ruby/data/sac.rb', line 30

def self.uri_for_self?(uri)
  ::SeisRuby::Data::Sac::Binary.uri_for_self?(uri) || ::SeisRuby::Data::Sac::Ascii.uri_for_self?(uri)
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
73
# File 'lib/seis_ruby/data/sac.rb', line 70

def ==(other)
  @head == other.head\
  && @body == other.body
end

#dump(type = :binary) ⇒ Object



54
55
56
# File 'lib/seis_ruby/data/sac.rb', line 54

def dump(type = :binary)
  module_from_type(type).dump(@head, @body)
end

#dump_file(file) ⇒ Object



47
48
49
50
51
52
# File 'lib/seis_ruby/data/sac.rb', line 47

def dump_file(file)
  open(file, 'wb'){|io|
    io.write(module_from_type(type_from_file(file)).dump(@head, @body))
    io.flush
  }
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/seis_ruby/data/sac.rb', line 58

def eql?(other)
  self.class == other.class\
  && @meta_data.eql?(other.)\
  && @raw_data.eql?(other.raw_data)\
  && @head.eql?(other.head)\
  && @body.eql?(other.body)
end

#hashObject



66
67
68
# File 'lib/seis_ruby/data/sac.rb', line 66

def hash
  [self.class, @meta_data, @raw_data, @head, @body].hash
end