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
@@ -1,156 +1,149 @@
1
- require 'nokogiri'
2
-
3
1
  module LiteXBRL
4
2
  module TDnet
5
- class Summary
6
- extend Utils
7
-
8
- attr_accessor :code, :year, :quarter,
9
- :net_sales, :operating_income, :ordinary_income, :net_income, :net_income_per_share
10
-
11
- # 名前空間
12
- NS = {
13
- 'xbrli' => 'http://www.xbrl.org/2003/instance',
14
- 'tse-t-ed' => 'http://www.xbrl.tdnet.info/jp/br/tdnet/t/ed/2007-06-30'
15
- }
16
-
17
- class << self
18
- def parse(path)
19
- doc = File.open(path) {|f| Nokogiri::XML f }
20
- read doc
21
- end
3
+ class Summary < FinancialInformation
4
+ include SummaryAttribute
22
5
 
23
- def parse_string(str)
24
- doc = Nokogiri::XML str
25
- read doc
26
- end
6
+ def self.read(doc)
7
+ xbrl = read_data doc
27
8
 
28
- private
29
-
30
- def read(doc)
31
- consolidation, season = find_consolidation_and_season(doc)
32
- context = context_hash(consolidation, season)
33
-
34
- xbrl = Summary.new
35
-
36
- # 証券コード
37
- xbrl.code = find_securities_code(doc, consolidation)
38
- # 会計年度
39
- xbrl.year = find_year(doc, consolidation)
40
- # 四半期
41
- xbrl.quarter = find_quarter(doc, consolidation, context)
42
-
43
- # 売上高
44
- xbrl.net_sales = to_mill(find_value(doc, "NetSales", context[:context_duration]))
45
- # 営業利益
46
- xbrl.operating_income = to_mill(find_value(doc, "OperatingIncome", context[:context_duration]))
47
- # 経常利益
48
- xbrl.ordinary_income = to_mill(find_value(doc, "OrdinaryIncome", context[:context_duration]))
49
- # 純利益
50
- xbrl.net_income = to_mill(find_value(doc, "NetIncome", context[:context_duration]))
51
- # 1株当たり純利益
52
- xbrl.net_income_per_share = find_value(doc, "NetIncomePerShare", context[:context_duration]).to_f
53
-
54
- xbrl
55
- end
9
+ {summary: xbrl.attributes,
10
+ results_forecast: [xbrl.attributes_results_forecast]}
11
+ end
56
12
 
57
- def find_consolidation_and_season(doc)
58
- consolidation = find_consolidation(doc)
59
- season = find_season(doc, consolidation)
13
+ private
60
14
 
61
- # 連結で取れない場合、非連結にする
62
- unless season
63
- consolidation = "NonConsolidated"
64
- season = find_season(doc, consolidation)
65
- end
15
+ def self.read_data(doc)
16
+ xbrl, context = find_base_data(doc)
66
17
 
67
- return consolidation, season
68
- end
18
+ find_data(doc, xbrl, context)
19
+ end
69
20
 
70
- #
71
- # 連結・非連結を取得します
72
- #
73
- def find_consolidation(doc)
74
- cons = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYearConsolidatedDuration']/xbrli:entity/xbrli:identifier", NS)
75
- non_cons = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYearNonConsolidatedDuration']/xbrli:entity/xbrli:identifier", NS)
76
-
77
- if cons
78
- "Consolidated"
79
- elsif non_cons
80
- "NonConsolidated"
81
- else
82
- raise StandardError.new("連結・非連結ともに該当しません。")
83
- end
84
- end
21
+ def self.find_base_data(doc)
22
+ consolidation, season = find_consolidation_and_season(doc)
23
+ context = context_hash(consolidation, season)
85
24
 
86
- #
87
- # 通期・四半期を取得します
88
- #
89
- def find_season(doc, consolidation)
90
- year = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Instant']/xbrli:entity/xbrli:identifier", NS)
91
- quarter = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentQuarter#{consolidation}Instant']/xbrli:entity/xbrli:identifier", NS)
92
- q1 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ1#{consolidation}Instant']/xbrli:entity/xbrli:identifier", NS)
93
- q2 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ2#{consolidation}Instant']/xbrli:entity/xbrli:identifier", NS)
94
- q3 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ3#{consolidation}Instant']/xbrli:entity/xbrli:identifier", NS)
95
-
96
- if year
97
- "Year"
98
- elsif quarter
99
- "Quarter"
100
- elsif q1
101
- "AccumulatedQ1"
102
- elsif q2
103
- "AccumulatedQ2"
104
- elsif q3
105
- "AccumulatedQ3"
106
- end
107
- end
25
+ xbrl = new
108
26
 
109
- #
110
- # contextを設定します
111
- #
112
- def context_hash(consolidation, season)
113
- raise StandardError.new("通期・四半期が設定されていません。") unless season
27
+ # 証券コード
28
+ xbrl.code = find_securities_code(doc, consolidation)
29
+ # 決算年
30
+ xbrl.year = find_year(doc, consolidation)
31
+ # 決算月
32
+ xbrl.month = find_month(doc, consolidation)
33
+ # 四半期
34
+ xbrl.quarter = find_quarter(doc, consolidation, context)
114
35
 
115
- {
116
- context_duration: "Current#{season}#{consolidation}Duration",
117
- context_instant: "Current#{season}#{consolidation}Instant"
118
- }
119
- end
36
+ return xbrl, context
37
+ end
120
38
 
121
- #
122
- # 証券コードを取得します
123
- #
124
- def find_securities_code(doc, consolidation)
125
- elm_code = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:entity/xbrli:identifier", NS)
126
- to_securities_code(elm_code)
127
- end
39
+ def self.find_consolidation_and_season(doc)
40
+ consolidation = find_consolidation(doc)
41
+ season = find_season(doc, consolidation)
128
42
 
129
- #
130
- # 会計年度を取得します
131
- #
132
- def find_year(doc, consolidation)
133
- elm_end = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:period/xbrli:endDate", NS)
134
- to_year(elm_end)
43
+ # 連結で取れない場合、非連結にする
44
+ unless season
45
+ consolidation = "NonConsolidated"
46
+ season = find_season(doc, consolidation)
135
47
  end
136
48
 
137
- #
138
- # 四半期を取得します
139
- #
140
- def find_quarter(doc, consolidation, context)
141
- elm_end = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Duration']/xbrli:period/xbrli:endDate", NS)
142
- elm_instant = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='#{context[:context_instant]}']/xbrli:period/xbrli:instant", NS)
143
- to_quarter(elm_end, elm_instant)
144
- end
49
+ return consolidation, season
50
+ end
145
51
 
146
- #
147
- # 勘定科目の値を取得します
148
- #
149
- def find_value(doc, item, context)
150
- doc.at_xpath("//xbrli:xbrl/tse-t-ed:#{item}[@contextRef='#{context}']", NS).content
52
+ #
53
+ # 通期・四半期を取得します
54
+ #
55
+ def self.find_season(doc, consolidation)
56
+ year = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentYear#{consolidation}Instant']/xbrli:entity/xbrli:identifier")
57
+ quarter = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentQuarter#{consolidation}Instant']/xbrli:entity/xbrli:identifier")
58
+ q1 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ1#{consolidation}Instant']/xbrli:entity/xbrli:identifier")
59
+ q2 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ2#{consolidation}Instant']/xbrli:entity/xbrli:identifier")
60
+ q3 = doc.at_xpath("//xbrli:xbrl/xbrli:context[@id='CurrentAccumulatedQ3#{consolidation}Instant']/xbrli:entity/xbrli:identifier")
61
+
62
+ if year
63
+ "Year"
64
+ elsif quarter
65
+ "Quarter"
66
+ elsif q1
67
+ "AccumulatedQ1"
68
+ elsif q2
69
+ "AccumulatedQ2"
70
+ elsif q3
71
+ "AccumulatedQ3"
151
72
  end
152
73
  end
153
74
 
75
+ def self.find_data(doc, xbrl, context)
76
+ # 売上高
77
+ xbrl.net_sales = find_value_to_mill(doc, NET_SALES, context[:context_duration])
78
+ # 営業利益
79
+ xbrl.operating_income = find_value_to_mill(doc, OPERATING_INCOME, context[:context_duration])
80
+ # 経常利益
81
+ xbrl.ordinary_income = find_value_to_mill(doc, ORDINARY_INCOME, context[:context_duration])
82
+ # 純利益
83
+ xbrl.net_income = find_value_to_mill(doc, NET_INCOME, context[:context_duration])
84
+ # 1株当たり純利益
85
+ xbrl.net_income_per_share = find_value_to_f(doc, NET_INCOME_PER_SHARE, context[:context_duration])
86
+
87
+ # 売上高前年比
88
+ xbrl.change_in_net_sales = find_value_to_f(doc, CHANGE_IN_NET_SALES, context[:context_duration])
89
+ # 営業利益前年比
90
+ xbrl.change_in_operating_income = find_value_to_f(doc, CHANGE_IN_OPERATING_INCOME, context[:context_duration])
91
+ # 経常利益前年比
92
+ xbrl.change_in_ordinary_income = find_value_to_f(doc, CHANGE_IN_ORDINARY_INCOME, context[:context_duration])
93
+ # 純利益前年比
94
+ xbrl.change_in_net_income = find_value_to_f(doc, CHANGE_IN_NET_INCOME, context[:context_duration])
95
+
96
+ # 前期売上高
97
+ xbrl.prior_net_sales = find_value_to_mill(doc, NET_SALES, context[:context_prior_duration])
98
+ # 前期営業利益
99
+ xbrl.prior_operating_income = find_value_to_mill(doc, OPERATING_INCOME, context[:context_prior_duration])
100
+ # 前期経常利益
101
+ xbrl.prior_ordinary_income = find_value_to_mill(doc, ORDINARY_INCOME, context[:context_prior_duration])
102
+ # 前期純利益
103
+ xbrl.prior_net_income = find_value_to_mill(doc, NET_INCOME, context[:context_prior_duration])
104
+ # 前期1株当たり純利益
105
+ xbrl.prior_net_income_per_share = find_value_to_f(doc, NET_INCOME_PER_SHARE, context[:context_prior_duration])
106
+
107
+ # 前期売上高前年比
108
+ xbrl.change_in_prior_net_sales = find_value_to_f(doc, CHANGE_IN_NET_SALES, context[:context_prior_duration])
109
+ # 前期営業利益前年比
110
+ xbrl.change_in_prior_operating_income = find_value_to_f(doc, CHANGE_IN_OPERATING_INCOME, context[:context_prior_duration])
111
+ # 前期経常利益前年比
112
+ xbrl.change_in_prior_ordinary_income = find_value_to_f(doc, CHANGE_IN_ORDINARY_INCOME, context[:context_prior_duration])
113
+ # 前期純利益前年比
114
+ xbrl.change_in_prior_net_income = find_value_to_f(doc, CHANGE_IN_NET_INCOME, context[:context_prior_duration])
115
+
116
+ # 通期予想売上高
117
+ xbrl.forecast_net_sales = find_value_to_mill(doc, FORECAST_NET_SALES, context[:context_forecast].call(xbrl.quarter))
118
+ # 通期予想営業利益
119
+ xbrl.forecast_operating_income = find_value_to_mill(doc, FORECAST_OPERATING_INCOME, context[:context_forecast].call(xbrl.quarter))
120
+ # 通期予想経常利益
121
+ xbrl.forecast_ordinary_income = find_value_to_mill(doc, FORECAST_ORDINARY_INCOME, context[:context_forecast].call(xbrl.quarter))
122
+ # 通期予想純利益
123
+ xbrl.forecast_net_income = find_value_to_mill(doc, FORECAST_NET_INCOME, context[:context_forecast].call(xbrl.quarter))
124
+ # 通期予想1株当たり純利益
125
+ xbrl.forecast_net_income_per_share = find_value_to_f(doc, FORECAST_NET_INCOME_PER_SHARE, context[:context_forecast].call(xbrl.quarter))
126
+
127
+ # 通期予想売上高前年比
128
+ xbrl.change_in_forecast_net_sales = find_value_to_f(doc, CHANGE_FORECAST_NET_SALES, context[:context_forecast].call(xbrl.quarter))
129
+ # 通期予想営業利益前年比
130
+ xbrl.change_in_forecast_operating_income = find_value_to_f(doc, CHANGE_FORECAST_OPERATING_INCOME, context[:context_forecast].call(xbrl.quarter))
131
+ # 通期予想経常利益前年比
132
+ xbrl.change_in_forecast_ordinary_income = find_value_to_f(doc, CHANGE_FORECAST_ORDINARY_INCOME, context[:context_forecast].call(xbrl.quarter))
133
+ # 通期予想純利益前年比
134
+ xbrl.change_in_forecast_net_income = find_value_to_f(doc, CHANGE_FORECAST_NET_INCOME, context[:context_forecast].call(xbrl.quarter))
135
+
136
+ xbrl
137
+ end
138
+
139
+ def self.find_value_to_mill(doc, item, context)
140
+ to_mill find_value_tse_t_ed(doc, item, context)
141
+ end
142
+
143
+ def self.find_value_to_f(doc, item, context)
144
+ to_f find_value_tse_t_ed(doc, item, context)
145
+ end
146
+
154
147
  end
155
148
  end
156
149
  end
@@ -0,0 +1,178 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ class Summary2 < FinancialInformation2
4
+ include SummaryAttribute, CompanyAttribute
5
+
6
+ def self.read(doc)
7
+ xbrl = read_data doc
8
+
9
+ {summary: xbrl.attributes,
10
+ results_forecast: [xbrl.attributes_results_forecast]}
11
+ end
12
+
13
+ private
14
+
15
+ def self.read_data(doc)
16
+ xbrl, context = find_base_data(doc)
17
+
18
+ find_data(doc, xbrl, context)
19
+ end
20
+
21
+ def self.find_base_data(doc)
22
+ season = find_season(doc)
23
+ consolidation = find_consolidation(doc, season)
24
+ context = context_hash(consolidation, season)
25
+
26
+ xbrl = new
27
+
28
+ # 証券コード
29
+ xbrl.code = find_securities_code(doc, season)
30
+ # 決算年・決算月
31
+ xbrl.year, xbrl.month = find_year_and_month(doc)
32
+ # 四半期
33
+ xbrl.quarter = to_quarter(season)
34
+
35
+ return xbrl, context
36
+ end
37
+
38
+ #
39
+ # 通期・四半期を取得します
40
+ #
41
+ def self.find_season(doc)
42
+ q1 = doc.at_xpath("//ix:nonNumeric[@contextRef='CurrentAccumulatedQ1Instant' and @name='tse-ed-t:SecuritiesCode']")
43
+ q2 = doc.at_xpath("//ix:nonNumeric[@contextRef='CurrentAccumulatedQ2Instant' and @name='tse-ed-t:SecuritiesCode']")
44
+ q3 = doc.at_xpath("//ix:nonNumeric[@contextRef='CurrentAccumulatedQ3Instant' and @name='tse-ed-t:SecuritiesCode']")
45
+ year = doc.at_xpath("//ix:nonNumeric[@contextRef='CurrentYearInstant' and @name='tse-ed-t:SecuritiesCode']")
46
+
47
+ if q1
48
+ SEASON_Q1
49
+ elsif q2
50
+ SEASON_Q2
51
+ elsif q3
52
+ SEASON_Q3
53
+ elsif year
54
+ SEASON_Q4
55
+ else
56
+ raise StandardError.new("通期・四半期を取得出来ません。")
57
+ end
58
+ end
59
+
60
+ #
61
+ # 連結・非連結を取得します
62
+ #
63
+ def self.find_consolidation(doc, season)
64
+ cons = find_value_tse_ed_t(doc, NET_SALES, "Current#{season}Duration_ConsolidatedMember_ResultMember")
65
+ non_cons = find_value_tse_ed_t(doc, NET_SALES, "Current#{season}Duration_NonConsolidatedMember_ResultMember")
66
+
67
+ if cons
68
+ "Consolidated"
69
+ elsif non_cons
70
+ "NonConsolidated"
71
+ else
72
+ raise StandardError.new("連結・非連結ともに該当しません。")
73
+ end
74
+ end
75
+
76
+ #
77
+ # contextを設定します
78
+ #
79
+ def self.context_hash(consolidation, season)
80
+ year_duration = "YearDuration_#{consolidation}Member_ForecastMember"
81
+
82
+ {
83
+ context_duration: "Current#{season}Duration_#{consolidation}Member_ResultMember",
84
+ context_prior_duration: "Prior#{season}Duration_#{consolidation}Member_ResultMember",
85
+ context_instant: "Current#{season}Instant",
86
+ context_forecast: ->(quarter) { quarter == 4 ? "Next#{year_duration}" : "Current#{year_duration}"},
87
+ }
88
+ end
89
+
90
+ def self.find_data(doc, xbrl, context)
91
+ # 売上高
92
+ xbrl.net_sales = find_value_to_i(doc, NET_SALES, context[:context_duration])
93
+ # 営業利益
94
+ xbrl.operating_income = find_value_to_i(doc, OPERATING_INCOME, context[:context_duration])
95
+ # 経常利益
96
+ xbrl.ordinary_income = find_value_to_i(doc, ORDINARY_INCOME, context[:context_duration])
97
+ # 純利益
98
+ xbrl.net_income = find_value_to_i(doc, NET_INCOME, context[:context_duration])
99
+ # 1株当たり純利益
100
+ xbrl.net_income_per_share = find_value_to_f(doc, NET_INCOME_PER_SHARE, context[:context_duration])
101
+
102
+ # 売上高前年比
103
+ xbrl.change_in_net_sales = find_value_percent_to_f(doc, CHANGE_IN_NET_SALES, context[:context_duration])
104
+ # 営業利益前年比
105
+ xbrl.change_in_operating_income = find_value_percent_to_f(doc, CHANGE_IN_OPERATING_INCOME, context[:context_duration])
106
+ # 経常利益前年比
107
+ xbrl.change_in_ordinary_income = find_value_percent_to_f(doc, CHANGE_IN_ORDINARY_INCOME, context[:context_duration])
108
+ # 純利益前年比
109
+ xbrl.change_in_net_income = find_value_percent_to_f(doc, CHANGE_IN_NET_INCOME, context[:context_duration])
110
+
111
+ # 前期売上高
112
+ xbrl.prior_net_sales = find_value_to_i(doc, NET_SALES, context[:context_prior_duration])
113
+ # 前期営業利益
114
+ xbrl.prior_operating_income = find_value_to_i(doc, OPERATING_INCOME, context[:context_prior_duration])
115
+ # 前期経常利益
116
+ xbrl.prior_ordinary_income = find_value_to_i(doc, ORDINARY_INCOME, context[:context_prior_duration])
117
+ # 前期純利益
118
+ xbrl.prior_net_income = find_value_to_i(doc, NET_INCOME, context[:context_prior_duration])
119
+ # 前期1株当たり純利益
120
+ xbrl.prior_net_income_per_share = find_value_to_f(doc, NET_INCOME_PER_SHARE, context[:context_prior_duration])
121
+
122
+ # 前期売上高前年比
123
+ xbrl.change_in_prior_net_sales = find_value_percent_to_f(doc, CHANGE_IN_NET_SALES, context[:context_prior_duration])
124
+ # 前期営業利益前年比
125
+ xbrl.change_in_prior_operating_income = find_value_percent_to_f(doc, CHANGE_IN_OPERATING_INCOME, context[:context_prior_duration])
126
+ # 前期経常利益前年比
127
+ xbrl.change_in_prior_ordinary_income = find_value_percent_to_f(doc, CHANGE_IN_ORDINARY_INCOME, context[:context_prior_duration])
128
+ # 前期純利益前年比
129
+ xbrl.change_in_prior_net_income = find_value_percent_to_f(doc, CHANGE_IN_NET_INCOME, context[:context_prior_duration])
130
+
131
+ # 通期予想売上高
132
+ xbrl.forecast_net_sales = find_value_to_i(doc, NET_SALES, context[:context_forecast].call(xbrl.quarter))
133
+ # 通期予想営業利益
134
+ xbrl.forecast_operating_income = find_value_to_i(doc, OPERATING_INCOME, context[:context_forecast].call(xbrl.quarter))
135
+ # 通期予想経常利益
136
+ xbrl.forecast_ordinary_income = find_value_to_i(doc, ORDINARY_INCOME, context[:context_forecast].call(xbrl.quarter))
137
+ # 通期予想純利益
138
+ xbrl.forecast_net_income = find_value_to_i(doc, NET_INCOME, context[:context_forecast].call(xbrl.quarter))
139
+ # 通期予想1株当たり純利益
140
+ xbrl.forecast_net_income_per_share = find_value_to_f(doc, NET_INCOME_PER_SHARE, context[:context_forecast].call(xbrl.quarter))
141
+
142
+ # 通期予想売上高前年比
143
+ xbrl.change_in_forecast_net_sales = find_value_percent_to_f(doc, CHANGE_IN_NET_SALES, context[:context_forecast].call(xbrl.quarter))
144
+ # 通期予想営業利益前年比
145
+ xbrl.change_in_forecast_operating_income = find_value_percent_to_f(doc, CHANGE_IN_OPERATING_INCOME, context[:context_forecast].call(xbrl.quarter))
146
+ # 通期予想経常利益前年比
147
+ xbrl.change_in_forecast_ordinary_income = find_value_percent_to_f(doc, CHANGE_IN_ORDINARY_INCOME, context[:context_forecast].call(xbrl.quarter))
148
+ # 通期予想純利益前年比
149
+ xbrl.change_in_forecast_net_income = find_value_percent_to_f(doc, CHANGE_IN_NET_INCOME, context[:context_forecast].call(xbrl.quarter))
150
+
151
+ xbrl
152
+ end
153
+
154
+ def self.find_value_to_i(doc, item, context)
155
+ to_i find_value_tse_ed_t(doc, item, context)
156
+ end
157
+
158
+ def self.find_value_to_f(doc, item, context)
159
+ to_f find_value_tse_ed_t(doc, item, context)
160
+ end
161
+
162
+ def self.find_value_percent_to_f(doc, item, context)
163
+ percent_to_f find_value_tse_ed_t(doc, item, context)
164
+ end
165
+
166
+ def self.parse_company(str)
167
+ doc = Nokogiri::XML str
168
+ xbrl, context = find_base_data(doc)
169
+
170
+ # 企業名
171
+ xbrl.company_name = find_value_non_numeric(doc, COMPANY_NAME, context[:context_instant])
172
+
173
+ xbrl
174
+ end
175
+
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,60 @@
1
+ module LiteXBRL
2
+ module TDnet
3
+ module SummaryAttribute
4
+
5
+ attr_accessor :code, :year, :month, :quarter,
6
+ :net_sales, :operating_income, :ordinary_income, :net_income, :net_income_per_share,
7
+ :change_in_net_sales, :change_in_operating_income, :change_in_ordinary_income, :change_in_net_income,
8
+ :prior_net_sales, :prior_operating_income, :prior_ordinary_income, :prior_net_income, :prior_net_income_per_share,
9
+ :change_in_prior_net_sales, :change_in_prior_operating_income, :change_in_prior_ordinary_income, :change_in_prior_net_income,
10
+ :forecast_net_sales, :forecast_operating_income, :forecast_ordinary_income, :forecast_net_income, :forecast_net_income_per_share,
11
+ :change_in_forecast_net_sales, :change_in_forecast_operating_income, :change_in_forecast_ordinary_income, :change_in_forecast_net_income
12
+
13
+ def attributes
14
+ {
15
+ code: code,
16
+ year: year,
17
+ month: month,
18
+ quarter: quarter,
19
+ net_sales: net_sales,
20
+ operating_income: operating_income,
21
+ ordinary_income: ordinary_income,
22
+ net_income: net_income,
23
+ net_income_per_share: net_income_per_share,
24
+ change_in_net_sales: change_in_net_sales,
25
+ change_in_operating_income: change_in_operating_income,
26
+ change_in_ordinary_income: change_in_ordinary_income,
27
+ change_in_net_income: change_in_net_income,
28
+ prior_net_sales: prior_net_sales,
29
+ prior_operating_income: prior_operating_income,
30
+ prior_ordinary_income: prior_ordinary_income,
31
+ prior_net_income: prior_net_income,
32
+ prior_net_income_per_share: prior_net_income_per_share,
33
+ change_in_prior_net_sales: change_in_prior_net_sales,
34
+ change_in_prior_operating_income: change_in_prior_operating_income,
35
+ change_in_prior_ordinary_income: change_in_prior_ordinary_income,
36
+ change_in_prior_net_income: change_in_prior_net_income,
37
+ }
38
+ end
39
+
40
+ def attributes_results_forecast
41
+ {
42
+ code: code,
43
+ year: quarter == 4 ? year + 1 : year,
44
+ month: month,
45
+ quarter: 4,
46
+ forecast_net_sales: forecast_net_sales,
47
+ forecast_operating_income: forecast_operating_income,
48
+ forecast_ordinary_income: forecast_ordinary_income,
49
+ forecast_net_income: forecast_net_income,
50
+ forecast_net_income_per_share: forecast_net_income_per_share,
51
+ change_in_forecast_net_sales: change_in_forecast_net_sales,
52
+ change_in_forecast_operating_income: change_in_forecast_operating_income,
53
+ change_in_forecast_ordinary_income: change_in_forecast_ordinary_income,
54
+ change_in_forecast_net_income: change_in_forecast_net_income,
55
+ }
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -1,7 +1,71 @@
1
+ require 'litexbrl/tdnet/account_item'
2
+ require 'litexbrl/tdnet/summary_attribute'
3
+ require 'litexbrl/tdnet/results_forecast_attribute'
4
+ require 'litexbrl/tdnet/company_attribute'
5
+ require 'litexbrl/tdnet/financial_information'
1
6
  require 'litexbrl/tdnet/summary'
7
+ require 'litexbrl/tdnet/results_forecast'
8
+ require 'litexbrl/tdnet/financial_information2'
9
+ require 'litexbrl/tdnet/summary2'
10
+ require 'litexbrl/tdnet/results_forecast2'
2
11
 
3
12
  module LiteXBRL
4
13
  module TDnet
5
14
 
15
+ class << self
16
+
17
+ def parse(path)
18
+ doc = File.open(path) {|f| Nokogiri::XML f }
19
+ read doc
20
+ end
21
+
22
+ def parse_string(str)
23
+ doc = Nokogiri::XML str
24
+ read doc
25
+ end
26
+
27
+ private
28
+
29
+ def read(doc)
30
+ document = find_document doc
31
+
32
+ document.read doc
33
+ end
34
+
35
+ def find_document(doc)
36
+ namespaces = doc.namespaces
37
+
38
+ # TODO 委嬢する?
39
+ if summary? namespaces
40
+ Summary
41
+ elsif summary2? namespaces
42
+ Summary2
43
+ elsif results_forecast? namespaces
44
+ ResultsForecast
45
+ elsif results_forecast2? namespaces
46
+ ResultsForecast2
47
+ else
48
+ raise StandardError.new "ドキュメントがありません"
49
+ end
50
+ end
51
+
52
+ def summary?(namespaces)
53
+ namespaces.keys.any? {|ns| /tdnet-.+(jpsm|ussm|ifsm)/ =~ ns }
54
+ end
55
+
56
+ def summary2?(namespaces)
57
+ namespaces.keys.any? {|ns| /tse-.+(jpsm|ussm|ifsm)/ =~ ns }
58
+ end
59
+
60
+ def results_forecast?(namespaces)
61
+ namespaces.keys.any? {|ns| /tdnet-rvfc/ =~ ns }
62
+ end
63
+
64
+ def results_forecast2?(namespaces)
65
+ namespaces.keys.any? {|ns| /tse-rvfc/ =~ ns }
66
+ end
67
+
68
+ end
69
+
6
70
  end
7
71
  end