Class: Xbrlware::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/xbrlware-extras/context.rb

Defined Under Namespace

Classes: Period

Instance Method Summary collapse

Instance Method Details

#write_constructor(file, context_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xbrlware-extras/context.rb', line 4

def write_constructor(file, context_name)
  period_str = "nil"
  case
    when !@period
    when self.period.is_instant?
      period_str = "Date.parse(\"#{self.period.value}\")"
    when self.period.is_duration?
      period_str = "{"
      period_str += "\"start_date\" => Date.parse(\"#{self.period.value["start_date"].to_s}\"),"
      period_str +=   "\"end_date\" => Date.parse(\"#{self.period.value[  "end_date"].to_s}\")"
      period_str += "}"
  end

  entity_str = "nil"
  case
    when !@entity || !@entity.segment
    else
      identifier_str = "\"#{@entity.identifier}\""
      segment_str = "{}"
      entity_str = "Xbrlware::Entity.new(identifier=#{identifier_str}, segment=#{segment_str})"
  end

  file.puts "#{context_name} = Xbrlware::Factory.Context(:period => #{period_str}, :entity => #{entity_str})"
end