Class: Ziptz

Inherits:
Object
  • Object
show all
Defined in:
lib/ziptz.rb,
lib/version.rb

Constant Summary collapse

VERSION =
'5.1.2'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



5
6
7
# File 'lib/ziptz.rb', line 5

def self.instance
  @instance ||= new
end

Instance Method Details

#dbObject



9
10
11
12
13
14
15
# File 'lib/ziptz.rb', line 9

def db
  @db ||= begin
    db = SQLite3::Database.open(tz_data_path)
    db.results_as_hash = true
    db
  end
end

#inspectObject



42
43
44
# File 'lib/ziptz.rb', line 42

def inspect
  "#<#{self.class}:#{object_id}>"
end

#time_zone_name(zip) ⇒ Object



17
18
19
# File 'lib/ziptz.rb', line 17

def time_zone_name(zip)
  time_zone_info(zip)&.dig('time_zone')
end

#time_zone_offset(zip) ⇒ Object



21
22
23
# File 'lib/ziptz.rb', line 21

def time_zone_offset(zip)
  time_zone_info(zip)&.dig('offset')
end

#time_zone_uses_dst?(zip) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/ziptz.rb', line 25

def time_zone_uses_dst?(zip)
  tz_info = time_zone_info(zip)
  return unless tz_info

  tz_info['observes_dst'] == 1
end

#zips(tz_name) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/ziptz.rb', line 32

def zips(tz_name)
  sql = <<-SQL
    select zip_code
    from zip_codes
    where time_zone = ?
    order by zip_code
  SQL
  db.execute(sql, tz_name).map { |row| row['zip_code'] }
end