class TimeScales::Frame::PartDef

Attributes

key[R]
part[R]
value[R]

Public Class Methods

new(key, value=nil) click to toggle source
# File lib/time_scales/frame/part_def.rb, line 7
def initialize(key, value=nil)
  @key   = key
  @value = value
end

Public Instance Methods

component_of!(scope) click to toggle source
# File lib/time_scales/frame/part_def.rb, line 22
def component_of!(scope)
  @part = possible_parts.detect { |part|
    scope.subdivision === part.scope
  }
end
outer_scope!() click to toggle source
# File lib/time_scales/frame/part_def.rb, line 16
def outer_scope!
  @part = possible_parts.length == 1 ?
    possible_parts.first :
    possible_parts.detect { |part| part.default_for_unit? }
end
scale() click to toggle source
# File lib/time_scales/frame/part_def.rb, line 12
def scale
  possible_parts.first.scale
end

Private Instance Methods

possible_parts() click to toggle source
# File lib/time_scales/frame/part_def.rb, line 30
def possible_parts
  @possible_parts ||= begin
    parts = Parts.all.select { |part| part === key }
    if parts.empty?
      parts = Parts.all.select { |part| part.subdivision === key }
    end
    if parts.empty?
      raise NoPartOrUnitForKeyError, "No part or unit matches key #{key.inspect}"
    end
    parts
  end
end