Class: TimeStep::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/timesteps/timestepconverter.rb

Instance Method Summary collapse

Constructor Details

#initialize(reference, calendar: "standard", bc: false) ⇒ Converter

Returns a new instance of Converter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/timesteps/timestepconverter.rb', line 5

def initialize (reference, calendar: "standard", bc: false)
  @calendar = calendar
  @bc = bc
  case reference
  when String
    @reference = TimeStep.new(reference, calendar: calendar, bc: bc)
  when TimeStep
    @reference = reference
  else
    raise "first argument should be TimeStep or string"
  end
  @pair = {}
  @target = {}
  self["reference"] = reference
end

Instance Method Details

#[](name) ⇒ Object

Return target time step of the given name.



31
32
33
# File 'lib/timesteps/timestepconverter.rb', line 31

def [] (name)
  return @target[name]
end

#[]=(name, spec) ⇒ Object

Append or reset new target time step for the given name.



23
24
25
26
27
# File 'lib/timesteps/timestepconverter.rb', line 23

def []= (name, spec)
  @pair[name] = TimeStep::Pair.new(@reference, spec, calendar: @calendar, bc: @bc)
  @target[name] = @pair[name].to
  return @target[name]
end

#delete(name) ⇒ Object

Relete target of the given name.



37
38
39
40
# File 'lib/timesteps/timestepconverter.rb', line 37

def delete (name)
  @pair.delete(name)
  @target.delete(name)
end

#forward(*indices) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/timesteps/timestepconverter.rb', line 42

def forward (*indices)
  hash = {}
  @pair.each do |name, conv|
    hash[name] = conv.forward(*indices)
  end
  return hash
end

#time_at(index) ⇒ Object



58
59
60
# File 'lib/timesteps/timestepconverter.rb', line 58

def time_at (index)
  return @from.time_at(index)
end

#valid?(*indices) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/timesteps/timestepconverter.rb', line 50

def valid? (*indices)
  hash = {}
  @pair.each do |name, conv|
    hash[name] = conv.to.valid?(*conv.forward(*indices))
  end
  return hash
end