Class: Ruby::Rego::Builtins::Times::GoLayout::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/builtins/times/go_layout/parser.rb,
lib/ruby/rego/builtins/times/go_layout/parser/zones.rb,
lib/ruby/rego/builtins/times/go_layout/parser/fields.rb,
lib/ruby/rego/builtins/times/go_layout/parser/compose.rb,
lib/ruby/rego/builtins/times/go_layout/parser/consumers.rb

Overview

The per-token field consumers of the parser: each reads one layout token’s value from the input via the field primitives, accumulates the broken-down field, and returns a success boolean (false aborts the parse). Split from the primitives and the driver so each file stays under RubyCritic’s complexity budget; class path unchanged. rubocop:disable Naming/PredicateMethod – the consume_* helpers return a success boolean for control flow (false aborts the parse); they are not predicates. :reek:InstanceVariableAssumption – the ivars are set in Parser#initialize (parser.rb); this reopen only reads/updates the already-established broken-down fields.

Constant Summary collapse

SHORT_MONTHS =

Short (3-letter) month/weekday names, derived from the long tables GoLayout uses.

MONTHS.map { |name| name[0, 3] }.freeze
SHORT_WEEKDAYS =
WEEKDAYS.map { |name| name[0, 3] }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(layout, value) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • layout (String)

    a Go reference-time layout (named layouts already resolved)

  • value (String)

    the timestamp text to parse



63
64
65
66
67
68
69
70
# File 'lib/ruby/rego/builtins/times/go_layout/parser.rb', line 63

def initialize(layout, value)
  @layout = layout
  @value = value
  @year = @hour = @min = @sec = @nsec = 0
  @month = @day = @yday = -1
  @zone_offset = nil # nil == no zone seen (Go's -1); set to a signed seconds offset
  @pm = @am = false
end

Instance Method Details

#runInteger?

Returns epoch nanoseconds, or nil when the parse is undefined.

Returns:

  • (Integer, nil)

    epoch nanoseconds, or nil when the parse is undefined



73
74
75
# File 'lib/ruby/rego/builtins/times/go_layout/parser.rb', line 73

def run
  walk ? compose : nil
end