Class: Gribr::Degrib::File

Inherits:
File
  • Object
show all
Defined in:
lib/gribr/degrib/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(*params) ⇒ File

Returns a new instance of File.



9
10
11
# File 'lib/gribr/degrib/file.rb', line 9

def initialize(*params)
  super; validate!
end

Instance Method Details

#indexObject

Return the degrib index file.



14
15
16
# File 'lib/gribr/degrib/file.rb', line 14

def index
  @index ||= (indexed? ? Index.new(indexname) : Index.create(self))
end

#index!Object

Build the degrib index file.



19
20
21
# File 'lib/gribr/degrib/file.rb', line 19

def index!
  @index = Index.create!(self)
end

#indexed?Boolean

Return true if the degrib index file exists.

Returns:

  • (Boolean)


24
25
26
# File 'lib/gribr/degrib/file.rb', line 24

def indexed?
  File.exists?(indexname)
end

#indexnameObject

Returns the pathname of the degrib index file.



29
30
31
# File 'lib/gribr/degrib/file.rb', line 29

def indexname
  path.gsub(Regexp.new("#{File.extname(path)}$"), ".#{Index::EXTNAME}")
end

#inventory(options = {}) ⇒ Object

Returns the inventory of the file.



34
35
36
# File 'lib/gribr/degrib/file.rb', line 34

def inventory(options = {})
  @inventory ||= Inventory.file(self)
end

#messagesObject

Returns the messages in the grib file.



39
40
41
# File 'lib/gribr/degrib/file.rb', line 39

def messages
  @messages || inventory.records.map { |record| Message.new(self, record) }
end

#probe(latitude, longitude, options = { }, &block) ⇒ Object

Probe the grib file at the given location and return/yield the records.



45
46
47
# File 'lib/gribr/degrib/file.rb', line 45

def probe(latitude, longitude, options = { }, &block)
  probe_one(latitude, longitude, options, &block)
end