litexbrl 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/README.md +1 -1
  4. data/TODO.txt +8 -0
  5. data/bin/1.htm +2 -0
  6. data/bin/1q.htm +2 -0
  7. data/bin/ifrs-rev.htm +2 -0
  8. data/bin/ifrs.htm +2 -0
  9. data/bin/litexbrl +28 -0
  10. data/bin/mid.htm +2 -0
  11. data/bin/minus.htm +2 -0
  12. data/bin/non-cons.htm +2 -0
  13. data/bin/rev-non-cons.htm +2 -0
  14. data/bin/rev.htm +3986 -0
  15. data/bin/year.htm +2919 -0
  16. data/lib/litexbrl/tdnet/account_item.rb +111 -0
  17. data/lib/litexbrl/tdnet/company_attribute.rb +15 -0
  18. data/lib/litexbrl/tdnet/financial_information.rb +151 -0
  19. data/lib/litexbrl/tdnet/financial_information2.rb +97 -0
  20. data/lib/litexbrl/tdnet/results_forecast.rb +102 -0
  21. data/lib/litexbrl/tdnet/results_forecast2.rb +139 -0
  22. data/lib/litexbrl/tdnet/results_forecast_attribute.rb +35 -0
  23. data/lib/litexbrl/tdnet/summary.rb +127 -134
  24. data/lib/litexbrl/tdnet/summary2.rb +178 -0
  25. data/lib/litexbrl/tdnet/summary_attribute.rb +60 -0
  26. data/lib/litexbrl/tdnet.rb +64 -0
  27. data/lib/litexbrl/utils.rb +29 -35
  28. data/lib/litexbrl/version.rb +1 -1
  29. data/lib/litexbrl.rb +1 -1
  30. data/litexbrl.gemspec +4 -4
  31. data/spec/data/tdnet/results_forecast/ifrs-cons-2014.xbrl +4 -0
  32. data/spec/data/tdnet/results_forecast/jp-cons-2012.xbrl +6 -0
  33. data/spec/data/tdnet/results_forecast/jp-noncons-2014.xbrl +6 -0
  34. data/spec/data/tdnet/results_forecast/us-cons-2014.xbrl +8 -0
  35. data/spec/data/tdnet/results_forecast.xbrl +6 -0
  36. data/spec/data/tdnet/results_forecast2/1q.htm +2 -0
  37. data/spec/data/tdnet/results_forecast2/2q-4q.htm +2 -0
  38. data/spec/data/tdnet/results_forecast2/3q.htm +2 -0
  39. data/spec/data/tdnet/results_forecast2/ifrs-cons-2014.htm +2 -0
  40. data/spec/data/tdnet/results_forecast2/jp-cons-2014.htm +2 -0
  41. data/spec/data/tdnet/results_forecast2/jp-noncons-2014.htm +2 -0
  42. data/spec/data/tdnet/results_forecast2/range.htm +2 -0
  43. data/spec/data/tdnet/results_forecast2/us-cons-2014.htm +2 -0
  44. data/spec/data/tdnet/results_forecast2.htm +2 -0
  45. data/spec/data/tdnet/summary/ifrs-cons-2014-q1.xbrl +2 -0
  46. data/spec/data/tdnet/summary/ifrs-or-cons-2014-q1.xbrl +2 -0
  47. data/spec/data/tdnet/summary/ifrs-sa-cons-2014-q1.xbrl +5 -0
  48. data/spec/data/tdnet/summary/jp-bk-cons-2014-q1.xbrl +2 -0
  49. data/spec/data/tdnet/summary/jp-cons-2013-q4.xbrl +2 -0
  50. data/spec/data/tdnet/summary/jp-goprv-cons-2013-q4.xbrl +3 -0
  51. data/spec/data/tdnet/summary/jp-in-cons-2014-q1.xbrl +2 -0
  52. data/spec/data/tdnet/summary/jp-nsco-cons-2013-q4.xbrl +3 -0
  53. data/spec/data/tdnet/summary/jp-oprv-cons-2014-q1.xbrl +3 -0
  54. data/spec/data/tdnet/summary/jp-oprvsp-cons-2014-q1.xbrl +2 -0
  55. data/spec/data/tdnet/summary/jp-se-cons-2014-q1.xbrl +3 -0
  56. data/spec/data/tdnet/summary/us-bnip-cons-2014-q1.xbrl +5 -0
  57. data/spec/data/tdnet/summary/us-cons-2014-q1.xbrl +24 -0
  58. data/spec/data/tdnet/summary/us-ibmi-cons-2013-q4.xbrl +10 -0
  59. data/spec/data/tdnet/summary/us-ifco-cons-2013-q4.xbrl +6 -0
  60. data/spec/data/tdnet/summary/us-nsoprv-cons-2014-q1.xbrl +3 -0
  61. data/spec/data/tdnet/summary/us-oi-cons-2014-q1.xbrl +3 -0
  62. data/spec/data/tdnet/summary/us-oprv-cons-2014-q1.xbrl +3 -0
  63. data/spec/data/tdnet/summary/us-tr-ibit-cons-2013-q4.xbrl +3 -0
  64. data/spec/data/tdnet/summary2/ifrs-cons-2013-q4.htm +2 -0
  65. data/spec/data/tdnet/summary2/jp-cons-2013-q4.htm +2 -0
  66. data/spec/data/tdnet/summary2/jp-cons-2014-q1.htm +2 -0
  67. data/spec/data/tdnet/summary2/jp-noncons-2014-q4.htm +2 -0
  68. data/spec/data/tdnet/summary2/us-cons-2014-q4.htm +2 -0
  69. data/spec/data/tdnet/summary2.htm +2 -0
  70. data/spec/spec_helper.rb +0 -1
  71. data/spec/support/nokogiri_helper.rb +4 -0
  72. data/spec/tdnet/account_item_spec.rb +57 -0
  73. data/spec/tdnet/results_forecast2_spec.rb +257 -0
  74. data/spec/tdnet/results_forecast_attribute_spec.rb +58 -0
  75. data/spec/tdnet/results_forecast_spec.rb +112 -0
  76. data/spec/tdnet/summary2_spec.rb +247 -0
  77. data/spec/tdnet/summary_attribute_spec.rb +92 -0
  78. data/spec/tdnet/summary_spec.rb +543 -62
  79. data/spec/tdnet_spec.rb +41 -0
  80. data/spec/utils_spec.rb +74 -0
  81. metadata +144 -20
  82. /data/spec/data/tdnet/summary/{ja-cons-2013-q1.xbrl → jp-cons-2013-q1.xbrl} +0 -0
  83. /data/spec/data/tdnet/summary/{ja-cons-2013-q2.xbrl → jp-cons-2013-q2.xbrl} +0 -0
  84. /data/spec/data/tdnet/summary/{ja-cons-2013-q3.xbrl → jp-cons-2013-q3.xbrl} +0 -0
  85. /data/spec/data/tdnet/summary/{ja-noncons-q1.xbrl → jp-noncons-q1.xbrl} +0 -0
  86. /data/spec/data/tdnet/{summary/ja-cons-2013-q4.xbrl → summary.xbrl} +0 -0
@@ -0,0 +1,111 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ module AccountItem
4
+
5
+ def self.define_item(items, &block)
6
+ items.map do |item|
7
+ block.call item
8
+ end.flatten
9
+ end
10
+
11
+ def self.define_nested_item(nested_items, &block)
12
+ nested_items.map do |items|
13
+ define_item(items, &block)
14
+ end
15
+ end
16
+
17
+ # 売上高
18
+ NET_SALES = ['NetSales', 'OrdinaryRevenuesBK', 'OperatingRevenuesSE', 'OrdinaryRevenuesIN', 'OperatingRevenues',
19
+ 'OperatingRevenuesSpecific', 'GrossOperatingRevenues', 'NetSalesOfCompletedConstructionContracts',
20
+ 'NetSalesUS', 'OperatingRevenuesUS', 'NetSalesAndOperatingRevenuesUS', 'TotalRevenuesUS',
21
+ 'NetSalesIFRS', 'OperatingRevenuesIFRS', 'SalesIFRS']
22
+
23
+ # 営業利益
24
+ OPERATING_INCOME = [['OperatingIncome', 'OperatingIncomeUS', 'OperatingIncomeIFRS'],
25
+ ['OrdinaryIncome', 'IncomeBeforeIncomeTaxesUS', 'ProfitBeforeTaxIFRS']]
26
+
27
+ # 経常利益
28
+ ORDINARY_INCOME = ['OrdinaryIncome', 'IncomeBeforeIncomeTaxesUS', 'IncomeFromContinuingOperationsBeforeIncomeTaxesUS',
29
+ 'ProfitBeforeTaxIFRS', 'ProfitBeforeIncomeTaxIFRS']
30
+
31
+ # 純利益
32
+ NET_INCOME = ['NetIncome', 'NetIncomeUS', 'IncomeBeforeMinorityInterestUS', 'ProfitAttributableToOwnersOfParentIFRS']
33
+
34
+ # 一株当たり純利益
35
+ NET_INCOME_PER_SHARE = ['NetIncomePerShare', 'NetIncomePerShareUS', 'BasicNetIncomePerShareUS',
36
+ 'BasicEarningsPerShareIFRS', 'BasicEarningPerShareIFRS']
37
+
38
+ # 売上高前年比/通期予想売上高前年比
39
+ CHANGE_IN_NET_SALES = define_item(NET_SALES) {|item| ["ChangeIn#{item}", "ChangesIn#{item}"] }
40
+
41
+ # 営業利益前年比/通期予想営業利益前年比
42
+ CHANGE_IN_OPERATING_INCOME = define_nested_item(OPERATING_INCOME) {|item| ["ChangeIn#{item}", "ChangesIn#{item}"] }
43
+
44
+ # 経常利益前年比/通期予想経常利益前年比
45
+ CHANGE_IN_ORDINARY_INCOME = define_item(ORDINARY_INCOME) {|item| ["ChangeIn#{item}", "ChangesIn#{item}"] }
46
+
47
+ # 純利益前年比/通期予想純利益前年比
48
+ CHANGE_IN_NET_INCOME = define_item(NET_INCOME) {|item| ["ChangeIn#{item}", "ChangesIn#{item}"] }
49
+
50
+
51
+ # 通期/第2四半期予想売上高
52
+ FORECAST_NET_SALES = define_item(NET_SALES) {|item| "Forecast#{item}" }
53
+
54
+ # 通期/第2四半期予想営業利益
55
+ FORECAST_OPERATING_INCOME = define_nested_item(OPERATING_INCOME) {|item| "Forecast#{item}" }
56
+
57
+ # 通期/第2四半期予想経常利益
58
+ FORECAST_ORDINARY_INCOME = define_item(ORDINARY_INCOME) {|item| "Forecast#{item}" }
59
+
60
+ # 通期/第2四半期予想純利益
61
+ FORECAST_NET_INCOME = define_item(NET_INCOME) {|item| "Forecast#{item}" }
62
+
63
+ # 通期/第2四半期予想一株当たり純利益
64
+ FORECAST_NET_INCOME_PER_SHARE = define_item(NET_INCOME_PER_SHARE) {|item| "Forecast#{item}" }
65
+
66
+ # 通期予想売上高前年比
67
+ CHANGE_FORECAST_NET_SALES = define_item(NET_SALES) {|item| "ChangeForecast#{item}" }
68
+
69
+ # 通期予想営業利益前年比
70
+ CHANGE_FORECAST_OPERATING_INCOME = define_nested_item(OPERATING_INCOME) {|item| "ChangeForecast#{item}" }
71
+
72
+ # 通期予想経常利益前年比
73
+ CHANGE_FORECAST_ORDINARY_INCOME = define_item(ORDINARY_INCOME) {|item| "ChangeForecast#{item}" }
74
+
75
+ # 通期予想純利益前年比
76
+ CHANGE_FORECAST_NET_INCOME = define_item(NET_INCOME) {|item| "ChangeForecast#{item}" }
77
+
78
+
79
+ # 修正前通期/第2四半期予想売上高
80
+ PREVIOUS_FORECAST_NET_SALES = define_item(NET_SALES) {|item| "ForecastPrevious#{item}" }
81
+
82
+ # 修正前通期/第2四半期予想営業利益
83
+ PREVIOUS_FORECAST_OPERATING_INCOME = define_nested_item(OPERATING_INCOME) {|item| "ForecastPrevious#{item}" }
84
+
85
+ # 修正前通期/第2四半期予想経常利益
86
+ PREVIOUS_FORECAST_ORDINARY_INCOME = define_item(ORDINARY_INCOME) {|item| "ForecastPrevious#{item}" }
87
+
88
+ # 修正前通期/第2四半期予想純利益
89
+ PREVIOUS_FORECAST_NET_INCOME = define_item(NET_INCOME) {|item| "ForecastPrevious#{item}" }
90
+
91
+ # 修正前通期/第2四半期予想一株当たり純利益
92
+ PREVIOUS_FORECAST_NET_INCOME_PER_SHARE = define_item(NET_INCOME_PER_SHARE) {|item| "ForecastPrevious#{item}" }
93
+
94
+ # 通期/第2四半期予想売上高増減率
95
+ CHANGE_NET_SALES = define_item(NET_SALES) {|item| "Change#{item}" }
96
+
97
+ # 通期/第2四半期予想営業利益増減率
98
+ CHANGE_OPERATING_INCOME = define_nested_item(OPERATING_INCOME) {|item| "Change#{item}" }
99
+
100
+ # 通期/第2四半期予想経常利益増減率
101
+ CHANGE_ORDINARY_INCOME = define_item(ORDINARY_INCOME) {|item| "Change#{item}" }
102
+
103
+ # 通期/第2四半期予想純利益増減率
104
+ CHANGE_NET_INCOME = define_item(NET_INCOME) {|item| "Change#{item}" }
105
+
106
+ # 企業名
107
+ COMPANY_NAME = ['CompanyName']
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,15 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ module CompanyAttribute
4
+ attr_accessor :code, :company_name
5
+
6
+ def attributes_company
7
+ {
8
+ code: code,
9
+ company_name: company_name
10
+ }
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,151 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ class FinancialInformation
4
+ extend Utils
5
+ include AccountItem
6
+
7
+ class << self
8
+
9
+ private
10
+
11
+ def read(doc)
12
+ xbrl, accounting_base, context = find_base_data(doc)
13
+
14
+ find_data(doc, xbrl, accounting_base, context)
15
+ end
16
+
17
+ #
18
+ # 連結・非連結を取得します
19
+ #
20
+ def find_consolidation(doc)
21
+ cons = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYearConsolidatedDuration']/xbrli:entity/xbrli:identifier")
22
+ non_cons = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYearNonConsolidatedDuration']/xbrli:entity/xbrli:identifier")
23
+
24
+ if cons
25
+ "Consolidated"
26
+ elsif non_cons
27
+ "NonConsolidated"
28
+ else
29
+ raise StandardError.new("連結・非連結ともに該当しません。")
30
+ end
31
+ end
32
+
33
+ #
34
+ # contextを設定します
35
+ #
36
+ def context_hash(consolidation, season)
37
+ raise StandardError.new("通期・四半期が設定されていません。") unless season
38
+
39
+ year_duration = "Year#{consolidation}Duration"
40
+
41
+ {
42
+ context_duration: "Current#{season}#{consolidation}Duration",
43
+ context_prior_duration: "Prior#{season}#{consolidation}Duration",
44
+ context_instant: "Current#{season}#{consolidation}Instant",
45
+ context_forecast: ->(quarter) { quarter == 4 ? "Next#{year_duration}" : "Current#{year_duration}"},
46
+ }
47
+ end
48
+
49
+ #
50
+ # 証券コードを取得します
51
+ #
52
+ def find_securities_code(doc, consolidation)
53
+ elm_code = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:entity/xbrli:identifier")
54
+ to_securities_code(elm_code)
55
+ end
56
+
57
+ #
58
+ # 決算年を取得します
59
+ #
60
+ def find_year(doc, consolidation)
61
+ elm_end = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:period/xbrli:endDate")
62
+ to_year(elm_end)
63
+ end
64
+
65
+ #
66
+ # 決算月を取得します
67
+ #
68
+ def find_month(doc, consolidation)
69
+ elm_end = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:period/xbrli:endDate")
70
+ to_month(elm_end)
71
+ end
72
+
73
+ #
74
+ # 四半期を取得します
75
+ #
76
+ def find_quarter(doc, consolidation, context)
77
+ elm_end = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:period/xbrli:endDate")
78
+ elm_instant = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='#{context[:context_instant]}']/xbrli:period/xbrli:instant")
79
+ to_quarter(elm_end, elm_instant)
80
+ end
81
+
82
+ #
83
+ # 四半期を取得します
84
+ #
85
+ def to_quarter(elm_end, elm_instant)
86
+ raise StandardError.new("四半期を取得できません。") unless elm_end || elm_instant
87
+
88
+ month_end = elm_end.content.split('-')[1].to_i
89
+ month = elm_instant.content.split('-')[1].to_i
90
+
91
+ if month <= month_end
92
+ diff = month_end - month
93
+
94
+ if diff < 3
95
+ 4
96
+ elsif diff < 6
97
+ 3
98
+ elsif diff < 9
99
+ 2
100
+ else
101
+ 1
102
+ end
103
+ else
104
+ diff = month - month_end
105
+
106
+ if diff <= 3
107
+ 1
108
+ elsif diff <= 6
109
+ 2
110
+ elsif diff <= 9
111
+ 3
112
+ else
113
+ 4
114
+ end
115
+ end
116
+ end
117
+
118
+ #
119
+ # 決算短信サマリの勘定科目の値を取得します
120
+ #
121
+ def find_value_tse_t_ed(doc, item, context)
122
+ find_value(doc, item, context) do |item, context|
123
+ "//xbrli:xbrl/tse-t-ed:#{item}[@contextRef='#{context}']"
124
+ end
125
+ end
126
+
127
+ #
128
+ # 勘定科目の値を取得します
129
+ #
130
+ def find_value(doc, item, context)
131
+ # 配列の場合、いずれかに該当するもの
132
+ if item[0].is_a? String
133
+ xpath = item.map {|item| yield(item, context) }.join('|')
134
+ elm = doc.at_xpath xpath
135
+ elm.content if elm
136
+ # 2次元配列の場合、先頭の配列から優先に
137
+ elsif item[0].is_a? Array
138
+ item.each do |item|
139
+ xpath = item.map {|item| yield(item, context) }.join('|')
140
+ elm = doc.at_xpath xpath
141
+ return elm.content if elm
142
+ end
143
+
144
+ nil # 該当なし
145
+ end
146
+ end
147
+ end
148
+
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,97 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ class FinancialInformation2
4
+ extend Utils
5
+ include AccountItem
6
+
7
+ SEASON_Q1 = 'AccumulatedQ1'
8
+ SEASON_Q2 = 'AccumulatedQ2'
9
+ SEASON_Q3 = 'AccumulatedQ3'
10
+ SEASON_Q4 = 'Year'
11
+
12
+ class << self
13
+
14
+ private
15
+
16
+ #
17
+ # 証券コードを取得します
18
+ #
19
+ def find_securities_code(doc, season)
20
+ elm_code = doc.at_xpath("//ix:nonNumeric[@contextRef='Current#{season}Instant' and @name='tse-ed-t:SecuritiesCode']")
21
+ to_securities_code(elm_code)
22
+ end
23
+
24
+ #
25
+ # 決算年・決算月を取得します
26
+ #
27
+ def find_year_and_month(doc)
28
+ elm_end = doc.at_xpath("//xbrli:context[@id='CurrentYearDuration']/xbrli:period/xbrli:endDate")
29
+ return to_year(elm_end), to_month(elm_end)
30
+ end
31
+
32
+ #
33
+ # 四半期を取得します
34
+ #
35
+ def to_quarter(season)
36
+ case season
37
+ when SEASON_Q1
38
+ 1
39
+ when SEASON_Q2
40
+ 2
41
+ when SEASON_Q3
42
+ 3
43
+ when SEASON_Q4
44
+ 4
45
+ end
46
+ end
47
+
48
+ #
49
+ # 決算短信サマリの勘定科目の値を取得します
50
+ #
51
+ def find_value_tse_ed_t(doc, item, context)
52
+ find_value(doc, item, context) do |item, context|
53
+ "//ix:nonFraction[@contextRef='#{context}' and @name='tse-ed-t:#{item}']"
54
+ end
55
+ end
56
+
57
+ #
58
+ # 決算短信サマリの非数値の値を取得します
59
+ #
60
+ def find_value_non_numeric(doc, item, context)
61
+ find_value(doc, item, context) do |item, context|
62
+ "//ix:nonNumeric[@contextRef='#{context}' and @name='tse-ed-t:#{item}']"
63
+ end
64
+ end
65
+
66
+ #
67
+ # 勘定科目の値を取得します
68
+ #
69
+ def find_value(doc, item, context)
70
+ # 配列の場合、いずれかに該当するもの
71
+ if item[0].is_a? String
72
+ xpath = item.map {|item| yield(item, context) }.join('|')
73
+ elm = doc.at_xpath xpath
74
+ add_sign(elm) if elm
75
+ # 2次元配列の場合、先頭の配列から優先に
76
+ elsif item[0].is_a? Array
77
+ item.each do |item|
78
+ xpath = item.map {|item| yield(item, context) }.join('|')
79
+ elm = doc.at_xpath xpath
80
+ return add_sign(elm) if elm
81
+ end
82
+
83
+ nil # 該当なし
84
+ end
85
+ end
86
+
87
+ #
88
+ # マイナスが設定されていれば付加します
89
+ #
90
+ def add_sign(elm)
91
+ elm.attribute('sign') ? elm.attribute('sign').content + elm.content : elm.content
92
+ end
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,102 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ class ResultsForecast < FinancialInformation
4
+ include ResultsForecastAttribute
5
+
6
+ SEASON_Q2 = 'AccumulatedQ2'
7
+ SEASON_Q4 = 'Year'
8
+
9
+ def self.read(doc)
10
+ xbrl_q2 = read_data doc, SEASON_Q2
11
+ xbrl_q4 = read_data doc, SEASON_Q4
12
+
13
+ raise StandardError.new "業績予想の修正を取得できません。" unless xbrl_q2 || xbrl_q4
14
+
15
+ data = {results_forecast: []}
16
+ data[:results_forecast] << xbrl_q2.attributes if xbrl_q2
17
+ data[:results_forecast] << xbrl_q4.attributes if xbrl_q4
18
+
19
+ data
20
+ end
21
+
22
+ private
23
+
24
+ def self.read_data(doc, season)
25
+ xbrl, context = find_base_data(doc, season)
26
+
27
+ find_data(doc, xbrl, context)
28
+ end
29
+
30
+ def self.find_base_data(doc, season)
31
+ consolidation = find_consolidation(doc)
32
+ context = context_hash(consolidation, season)
33
+
34
+ xbrl = new
35
+
36
+ # 証券コード
37
+ xbrl.code = find_securities_code(doc, consolidation)
38
+ # 決算年
39
+ xbrl.year = find_year(doc, consolidation)
40
+ # 決算月
41
+ xbrl.month = find_month(doc, consolidation)
42
+ # 四半期
43
+ xbrl.quarter = season == SEASON_Q2 ? 2 : 4
44
+
45
+ return xbrl, context
46
+ end
47
+
48
+ def self.find_data(doc, xbrl, context)
49
+ # 通期/第2四半期予想売上高
50
+ xbrl.forecast_net_sales = to_mill find_value_ed(doc, FORECAST_NET_SALES, context)
51
+ # 通期/第2四半期予想営業利益
52
+ xbrl.forecast_operating_income = to_mill find_value_ed(doc, FORECAST_OPERATING_INCOME, context)
53
+ # 通期/第2四半期予想経常利益
54
+ xbrl.forecast_ordinary_income = to_mill find_value_ed(doc, FORECAST_ORDINARY_INCOME, context)
55
+ # 通期/第2四半期予想純利益
56
+ xbrl.forecast_net_income = to_mill find_value_ed(doc, FORECAST_NET_INCOME, context)
57
+ # 通期/第2四半期予想1株当たり純利益
58
+ xbrl.forecast_net_income_per_share = to_f find_value_ed(doc, FORECAST_NET_INCOME_PER_SHARE, context)
59
+
60
+ # 修正前通期/第2四半期予想売上高
61
+ xbrl.previous_forecast_net_sales = to_mill find_value_rv(doc, PREVIOUS_FORECAST_NET_SALES, context)
62
+ # 修正前通期/第2四半期予想営業利益
63
+ xbrl.previous_forecast_operating_income = to_mill find_value_rv(doc, PREVIOUS_FORECAST_OPERATING_INCOME, context)
64
+ # 修正前通期/第2四半期予想経常利益
65
+ xbrl.previous_forecast_ordinary_income = to_mill find_value_rv(doc, PREVIOUS_FORECAST_ORDINARY_INCOME, context)
66
+ # 修正前通期/第2四半期予想純利益
67
+ xbrl.previous_forecast_net_income = to_mill find_value_rv(doc, PREVIOUS_FORECAST_NET_INCOME, context)
68
+ # 修正前通期/第2四半期予想1株当たり純利益
69
+ xbrl.previous_forecast_net_income_per_share = to_f find_value_rv(doc, PREVIOUS_FORECAST_NET_INCOME_PER_SHARE, context)
70
+
71
+ # 通期/第2四半期予想売上高増減率
72
+ xbrl.change_forecast_net_sales = to_f find_value_rv(doc, CHANGE_NET_SALES, context)
73
+ # 通期/第2四半期予想営業利益増減率
74
+ xbrl.change_forecast_operating_income = to_f find_value_rv(doc, CHANGE_OPERATING_INCOME, context)
75
+ # 通期/第2四半期予想経常利益増減率
76
+ xbrl.change_forecast_ordinary_income = to_f find_value_rv(doc, CHANGE_ORDINARY_INCOME, context)
77
+ # 通期/第2四半期予想純利益増減率
78
+ xbrl.change_forecast_net_income = to_f find_value_rv(doc, CHANGE_NET_INCOME, context)
79
+
80
+ xbrl
81
+ end
82
+
83
+ def self.find_value_ed(doc, item, context)
84
+ find_value_tse_t_ed(doc, item, context[:context_duration])
85
+ end
86
+
87
+ def self.find_value_rv(doc, item, context)
88
+ find_value_tse_t_rv(doc, item, context[:context_duration])
89
+ end
90
+
91
+ #
92
+ # 修正報告の勘定科目の値を取得します
93
+ #
94
+ def self.find_value_tse_t_rv(doc, item, context)
95
+ find_value(doc, item, context) do |item, context|
96
+ "//xbrli:xbrl/tse-t-rv:#{item}[@contextRef='#{context}']"
97
+ end
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,139 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ class ResultsForecast2 < FinancialInformation2
4
+ include ResultsForecastAttribute
5
+
6
+ def self.read(doc)
7
+ xbrl_q2 = read_data doc, SEASON_Q2
8
+ xbrl_q4 = read_data doc, SEASON_Q4
9
+
10
+ unless xbrl_q2 || xbrl_q4
11
+ xbrl_q1 = read_data doc, SEASON_Q1
12
+ xbrl_q3 = read_data doc, SEASON_Q3 unless xbrl_q1
13
+
14
+ raise StandardError.new "業績予想の修正を取得できません。" unless xbrl_q1 || xbrl_q3
15
+ end
16
+
17
+ data = {results_forecast: []}
18
+ data[:results_forecast] << xbrl_q1.attributes if xbrl_q1
19
+ data[:results_forecast] << xbrl_q2.attributes if xbrl_q2
20
+ data[:results_forecast] << xbrl_q3.attributes if xbrl_q3
21
+ data[:results_forecast] << xbrl_q4.attributes if xbrl_q4
22
+
23
+ data
24
+ end
25
+
26
+ private
27
+
28
+ def self.read_data(doc, season)
29
+ consolidation = find_consolidation(doc, season, NET_SALES)
30
+ consolidation = find_consolidation(doc, season, OPERATING_INCOME) unless consolidation
31
+ consolidation = find_consolidation(doc, season, ORDINARY_INCOME) unless consolidation
32
+ consolidation = find_consolidation(doc, season, NET_INCOME) unless consolidation
33
+ consolidation = find_consolidation(doc, season, NET_INCOME_PER_SHARE) unless consolidation
34
+ consolidation = find_consolidation_range(doc, season, NET_SALES) unless consolidation
35
+ consolidation = find_consolidation_range(doc, season, OPERATING_INCOME) unless consolidation
36
+ consolidation = find_consolidation_range(doc, season, ORDINARY_INCOME) unless consolidation
37
+ consolidation = find_consolidation_range(doc, season, NET_INCOME) unless consolidation
38
+ consolidation = find_consolidation_range(doc, season, NET_INCOME_PER_SHARE) unless consolidation
39
+
40
+ return unless consolidation
41
+
42
+ xbrl,context = find_base_data(doc, consolidation, season)
43
+
44
+ find_data(doc, xbrl, context)
45
+ end
46
+
47
+ def self.find_consolidation(doc, season, item)
48
+ cons_current = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_ConsolidatedMember_CurrentMember_ForecastMember")
49
+ cons_prev = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_ConsolidatedMember_PreviousMember_ForecastMember")
50
+ non_cons_current = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_NonConsolidatedMember_CurrentMember_ForecastMember")
51
+ non_cons_prev = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_NonConsolidatedMember_PreviousMember_ForecastMember")
52
+
53
+ if cons_current || cons_prev
54
+ "Consolidated"
55
+ elsif non_cons_current || non_cons_prev
56
+ "NonConsolidated"
57
+ end
58
+ end
59
+
60
+ def self.find_consolidation_range(doc, season, item)
61
+ cons_current = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_ConsolidatedMember_CurrentMember_UpperMember")
62
+ cons_prev = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_ConsolidatedMember_PreviousMember_UpperMember")
63
+ non_cons_current = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_NonConsolidatedMember_CurrentMember_UpperMember")
64
+ non_cons_prev = present? find_value_tse_ed_t(doc, item, "Current#{season}Duration_NonConsolidatedMember_PreviousMember_UpperMember")
65
+
66
+ if cons_current || cons_prev
67
+ "Consolidated"
68
+ elsif non_cons_current || non_cons_prev
69
+ "NonConsolidated"
70
+ end
71
+ end
72
+
73
+ def self.context_hash(consolidation, season)
74
+ {
75
+ context_current_forecast: "Current#{season}Duration_#{consolidation}Member_CurrentMember_ForecastMember",
76
+ context_prev_forecast: "Current#{season}Duration_#{consolidation}Member_PreviousMember_ForecastMember",
77
+ }
78
+ end
79
+
80
+ def self.find_base_data(doc, consolidation, season)
81
+ context = context_hash(consolidation, season)
82
+ xbrl = new
83
+
84
+ # 証券コード
85
+ xbrl.code = find_securities_code(doc, SEASON_Q4)
86
+ # 決算年・決算月
87
+ xbrl.year, xbrl.month = find_year_and_month(doc)
88
+ # 四半期
89
+ xbrl.quarter = to_quarter season
90
+
91
+ return xbrl, context
92
+ end
93
+
94
+ def self.find_data(doc, xbrl, context)
95
+ # 通期/第2四半期予想売上高
96
+ xbrl.forecast_net_sales = to_i current_value(doc, NET_SALES, context)
97
+ # 通期/第2四半期予想営業利益
98
+ xbrl.forecast_operating_income = to_i current_value(doc, OPERATING_INCOME, context)
99
+ # 通期/第2四半期予想経常利益
100
+ xbrl.forecast_ordinary_income = to_i current_value(doc, ORDINARY_INCOME, context)
101
+ # 通期/第2四半期予想純利益
102
+ xbrl.forecast_net_income = to_i current_value(doc, NET_INCOME, context)
103
+ # 通期/第2四半期予想1株当たり純利益
104
+ xbrl.forecast_net_income_per_share = to_f current_value(doc, NET_INCOME_PER_SHARE, context)
105
+
106
+ # 修正前通期/第2四半期予想売上高
107
+ xbrl.previous_forecast_net_sales = to_i prev_value(doc, NET_SALES, context)
108
+ # 修正前通期/第2四半期予想営業利益
109
+ xbrl.previous_forecast_operating_income = to_i prev_value(doc, OPERATING_INCOME, context)
110
+ # 修正前通期/第2四半期予想経常利益
111
+ xbrl.previous_forecast_ordinary_income = to_i prev_value(doc, ORDINARY_INCOME, context)
112
+ # 修正前通期/第2四半期予想純利益
113
+ xbrl.previous_forecast_net_income = to_i prev_value(doc, NET_INCOME, context)
114
+ # 修正前通期/第2四半期予想1株当たり純利益
115
+ xbrl.previous_forecast_net_income_per_share = to_f prev_value(doc, NET_INCOME_PER_SHARE, context)
116
+
117
+ # 通期/第2四半期予想売上高増減率
118
+ xbrl.change_forecast_net_sales = percent_to_f current_value(doc, CHANGE_IN_NET_SALES, context)
119
+ # 通期/第2四半期予想営業利益増減率
120
+ xbrl.change_forecast_operating_income = percent_to_f current_value(doc, CHANGE_IN_OPERATING_INCOME, context)
121
+ # 通期/第2四半期予想経常利益増減率
122
+ xbrl.change_forecast_ordinary_income = percent_to_f current_value(doc, CHANGE_IN_ORDINARY_INCOME, context)
123
+ # 通期/第2四半期予想純利益増減率
124
+ xbrl.change_forecast_net_income = percent_to_f current_value(doc, CHANGE_IN_NET_INCOME, context)
125
+
126
+ xbrl
127
+ end
128
+
129
+ def self.current_value(doc, item, context)
130
+ find_value_tse_ed_t(doc, item, context[:context_current_forecast])
131
+ end
132
+
133
+ def self.prev_value(doc, item, context)
134
+ find_value_tse_ed_t(doc, item, context[:context_prev_forecast])
135
+ end
136
+
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,35 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ module ResultsForecastAttribute
4
+
5
+ attr_accessor :code, :year, :month, :quarter,
6
+ :forecast_net_sales, :forecast_operating_income, :forecast_ordinary_income, :forecast_net_income, :forecast_net_income_per_share,
7
+ :previous_forecast_net_sales, :previous_forecast_operating_income, :previous_forecast_ordinary_income, :previous_forecast_net_income, :previous_forecast_net_income_per_share,
8
+ :change_forecast_net_sales, :change_forecast_operating_income, :change_forecast_ordinary_income, :change_forecast_net_income
9
+
10
+ def attributes
11
+ {
12
+ code: code,
13
+ year: year,
14
+ month: month,
15
+ quarter: quarter,
16
+ forecast_net_sales: forecast_net_sales,
17
+ forecast_operating_income: forecast_operating_income,
18
+ forecast_ordinary_income: forecast_ordinary_income,
19
+ forecast_net_income: forecast_net_income,
20
+ forecast_net_income_per_share: forecast_net_income_per_share,
21
+ previous_forecast_net_sales: previous_forecast_net_sales,
22
+ previous_forecast_operating_income: previous_forecast_operating_income,
23
+ previous_forecast_ordinary_income: previous_forecast_ordinary_income,
24
+ previous_forecast_net_income: previous_forecast_net_income,
25
+ previous_forecast_net_income_per_share: previous_forecast_net_income_per_share,
26
+ change_forecast_net_sales: change_forecast_net_sales,
27
+ change_forecast_operating_income: change_forecast_operating_income,
28
+ change_forecast_ordinary_income: change_forecast_ordinary_income,
29
+ change_forecast_net_income: change_forecast_net_income,
30
+ }
31
+ end
32
+
33
+ end
34
+ end
35
+ end