class Fugit::Nat::Slot

Attributes

_data0[RW]
_data1[RW]
key[R]

Public Class Methods

new(key, d0, d1=nil, opts=nil) click to toggle source
# File lib/fugit/nat.rb, line 559
def initialize(key, d0, d1=nil, opts=nil)
  d1, opts = d1.is_a?(Symbol) ? [ nil, d1 ] : [ d1, opts ]
  @key, @_data0, @_data1 = key, d0, d1
  @opts = (opts.is_a?(Symbol) ? { opts => true } : opts) || {}
end

Public Instance Methods

a() click to toggle source
# File lib/fugit/nat.rb, line 580
def a; [ data0, data1 ]; end
append(slot) click to toggle source
# File lib/fugit/nat.rb, line 569
def append(slot)
  @_data0, @_data1 = conflate(0, slot), conflate(1, slot)
  @opts.clear
  self
end
data0() click to toggle source
# File lib/fugit/nat.rb, line 564
def data0; @data0 ||= Array(@_data0); end
data1() click to toggle source
# File lib/fugit/nat.rb, line 565
def data1; @data1 ||= Array(@_data1); end
graded?() click to toggle source
# File lib/fugit/nat.rb, line 568
def graded?; weak || strong; end
inspect() click to toggle source
# File lib/fugit/nat.rb, line 574
def inspect
  a = [ @key, @_data0 ]
  a << @_data1 if @_data1 != nil
  a << @opts if @opts && @opts.keys.any?
  "(slot #{a.collect(&:inspect).join(' ')})"
end
strong() click to toggle source
# File lib/fugit/nat.rb, line 567
def strong; @opts[:strong]; end
weak() click to toggle source
# File lib/fugit/nat.rb, line 566
def weak; @opts[:weak]; end

Protected Instance Methods

conflate(index, slot) click to toggle source
# File lib/fugit/nat.rb, line 586
def conflate(index, slot)
  a, b = index == 0 ? [ @_data0, slot._data0 ] : [ @_data1, slot._data1 ]
  return a if b == nil
  return b if a == nil
  if ra = (index == 0 && slot.strong == 1 && hour_range)
    h0, h1 = ra[0], ra[1] - 1; return h0 == h1 ? h0 : "#{h0}-#{h1}"
  elsif rb = (index == 0 && strong == 1 && slot.hour_range)
    h0, h1 = rb[0], rb[1] - 1; return h0 == h1 ? h0 : "#{h0}-#{h1}"
  end
  return a if strong == index || strong == true
  return b if slot.strong == index || slot.strong == true
  return a if slot.weak == index || slot.weak == true
  return b if weak == index || weak == true
  return [ '*' ] if a == '*' && b == '*'
  to_a(a).concat(to_a(b))
end
hour_range() click to toggle source
# File lib/fugit/nat.rb, line 602
def hour_range
  m = (key == :hm && @_data1 == 0 && @_data0.match(/\A(\d+)-(\d+)\z/))
  m ? [ m[1].to_i, m[2].to_i ] : nil
end
to_a(x) click to toggle source
# File lib/fugit/nat.rb, line 582
def to_a(x)
  return [] if x == '*'
  Array(x)
end