Module: IERS::Parsers::LeapSecond
- Defined in:
- lib/iers/parsers/leap_second.rb
Defined Under Namespace
Classes: Entry, Metadata, Table
Constant Summary collapse
- EXPIRES_ON =
/File expires on\s+(\d{1,2})\s+([A-Za-z]+)\s+(\d{4})/i- UPDATED_THROUGH =
/\AUpdated through\s+(.+?)\s*\z/i- COMMENT_PREFIX =
/\A#+\s*/
Class Method Summary collapse
Class Method Details
.parse(path) ⇒ Table
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/iers/parsers/leap_second.rb', line 25 def parse(path) path = Pathname(path) unless path.exist? raise FileNotFoundError.new( "File not found: #{path}", path: path.to_s ) end entries = [] expires_on = nil updated_through = nil path.each_line.with_index(1) do |line, line_number| stripped = line.scrub.strip next if stripped.empty? if stripped.start_with?("#") comment = stripped.sub(COMMENT_PREFIX, "") expires_on ||= parse_expiry(comment) updated_through ||= parse_updated_through(comment) next end entries << parse_line(line, path, line_number) end Table.new( entries: entries.freeze, metadata: Metadata.new( expires_on: expires_on, updated_through: updated_through ) ) end |