Module: LiteXBRL::Utils

Included in:
TDnet::FinancialInformation, TDnet::FinancialInformation2
Defined in:
lib/litexbrl/utils.rb

Instance Method Summary collapse

Instance Method Details

#hash_with_default(default, hash) ⇒ Object



4
5
6
7
# File 'lib/litexbrl/utils.rb', line 4

def hash_with_default(default, hash)
  hash.default = default
  hash
end

#percent_to_f(val) ⇒ Object



51
52
53
# File 'lib/litexbrl/utils.rb', line 51

def percent_to_f(val)
  (to_f(val) / 100).round(3) if present? val
end

#present?(val) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/litexbrl/utils.rb', line 55

def present?(val)
  val && val != ""
end

#to_f(val) ⇒ Object



47
48
49
# File 'lib/litexbrl/utils.rb', line 47

def to_f(val)
  val.delete(',').to_f if present? val
end

#to_i(val) ⇒ Object



43
44
45
# File 'lib/litexbrl/utils.rb', line 43

def to_i(val)
  val.delete(',').to_i if present? val
end

#to_mill(val) ⇒ Object

単位を100万円にします



39
40
41
# File 'lib/litexbrl/utils.rb', line 39

def to_mill(val)
  val.to_i / (1000 * 1000) if present? val
end

#to_month(elm_end) ⇒ Object

決算月を取得します

Raises:

  • (StandardError)


30
31
32
33
34
# File 'lib/litexbrl/utils.rb', line 30

def to_month(elm_end)
  raise StandardError.new("決算月を取得できません。") unless elm_end

  elm_end.content.split('-')[1].to_i
end

#to_securities_code(elm_code) ⇒ Object

証券コードを取得します

Raises:

  • (StandardError)


12
13
14
15
16
# File 'lib/litexbrl/utils.rb', line 12

def to_securities_code(elm_code)
  raise StandardError.new("証券コードを取得できません。") unless elm_code

  elm_code.content.slice(0, 4).tr("0-9", "0-9")
end

#to_year(elm_end) ⇒ Object

決算年を取得します

Raises:

  • (StandardError)


21
22
23
24
25
# File 'lib/litexbrl/utils.rb', line 21

def to_year(elm_end)
  raise StandardError.new("決算年を取得できません。") unless elm_end

  elm_end.content.split('-')[0].to_i
end