xbrlware-ce 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/ReleaseNotes.txt +23 -5
  2. data/doc/classes/Edgar/RSSFeedDownloader.html +2 -2
  3. data/doc/classes/NSAware.html +135 -0
  4. data/doc/classes/Xbrlware.html +1 -6
  5. data/doc/classes/Xbrlware/Context.html +85 -78
  6. data/doc/classes/Xbrlware/Context/Period.html +49 -49
  7. data/doc/classes/Xbrlware/Entity.html +49 -49
  8. data/doc/classes/Xbrlware/Identifier.html +14 -14
  9. data/doc/classes/Xbrlware/Instance.html +173 -98
  10. data/doc/classes/Xbrlware/Item.html +62 -25
  11. data/doc/classes/Xbrlware/Linkbase/CalculationLinkbase.html +41 -3
  12. data/doc/classes/Xbrlware/Linkbase/CalculationLinkbase/Calculation.html +1 -1
  13. data/doc/classes/Xbrlware/Linkbase/CalculationLinkbase/Calculation/CalculationArc.html +1 -1
  14. data/doc/classes/Xbrlware/Linkbase/DefinitionLinkbase.html +43 -3
  15. data/doc/classes/Xbrlware/Linkbase/DefinitionLinkbase/Definition.html +2 -2
  16. data/doc/classes/Xbrlware/Linkbase/DefinitionLinkbase/Definition/DefinitionArc.html +1 -1
  17. data/doc/classes/Xbrlware/Linkbase/LabelLinkbase/Label.html +1 -1
  18. data/doc/classes/Xbrlware/Linkbase/Linkbase/Link/Arc.html +22 -7
  19. data/doc/classes/Xbrlware/Linkbase/PresentationLinkbase.html +41 -3
  20. data/doc/classes/Xbrlware/Linkbase/PresentationLinkbase/Presentation.html +2 -8
  21. data/doc/classes/Xbrlware/Linkbase/PresentationLinkbase/Presentation/PresentationArc.html +1 -1
  22. data/doc/classes/Xbrlware/Taxonomy.html +84 -51
  23. data/doc/classes/Xbrlware/TaxonomyDefintion.html +14 -14
  24. data/doc/classes/Xbrlware/Unit.html +14 -7
  25. data/doc/classes/Xbrlware/Unit/Divide.html +7 -7
  26. data/doc/created.rid +1 -1
  27. data/doc/files/lib/edgar/edgar_data_downloader_rb.html +1 -1
  28. data/doc/files/lib/edgar_rb.html +1 -1
  29. data/doc/files/lib/xbrlware/context_rb.html +1 -1
  30. data/doc/files/lib/xbrlware/instance_rb.html +1 -1
  31. data/doc/files/lib/xbrlware/item_rb.html +1 -1
  32. data/doc/files/lib/xbrlware/linkbase/calculation_linkbase_rb.html +1 -1
  33. data/doc/files/lib/xbrlware/linkbase/definition_linkbase_rb.html +1 -1
  34. data/doc/files/lib/xbrlware/linkbase/label_linkbase_rb.html +1 -1
  35. data/doc/files/lib/xbrlware/linkbase/linkbase_rb.html +1 -1
  36. data/doc/files/lib/xbrlware/linkbase/presentation_linkbase_rb.html +1 -1
  37. data/doc/files/lib/xbrlware/{report_rb.html → ns_aware_rb.html} +10 -4
  38. data/doc/files/lib/xbrlware/taxonomy_rb.html +1 -1
  39. data/doc/files/lib/xbrlware/unit_rb.html +1 -1
  40. data/doc/files/lib/xbrlware/util_rb.html +1 -1
  41. data/doc/files/lib/xbrlware/version_rb.html +1 -1
  42. data/doc/files/lib/xbrlware/xml_parser_rb.html +1 -1
  43. data/doc/files/lib/xbrlware_rb.html +3 -1
  44. data/doc/fr_class_index.html +1 -1
  45. data/doc/fr_file_index.html +1 -1
  46. data/doc/fr_method_index.html +68 -68
  47. data/doc/index.html +2 -2
  48. data/example/callb/calculation_elements.rb +33 -0
  49. data/example/callb/calculation_elements_to_table.rb +62 -0
  50. data/example/case_study/cash_analyzer.rb +27 -0
  51. data/lib/edgar/edgar_data_downloader.rb +6 -6
  52. data/lib/xbrlware.rb +2 -0
  53. data/lib/xbrlware/context.rb +2 -0
  54. data/lib/xbrlware/instance.rb +65 -26
  55. data/lib/xbrlware/item.rb +34 -26
  56. data/lib/xbrlware/linkbase/calculation_linkbase.rb +51 -7
  57. data/lib/xbrlware/linkbase/definition_linkbase.rb +42 -2
  58. data/lib/xbrlware/linkbase/label_linkbase.rb +1 -0
  59. data/lib/xbrlware/linkbase/linkbase.rb +19 -9
  60. data/lib/xbrlware/linkbase/presentation_linkbase.rb +52 -9
  61. data/lib/xbrlware/ns_aware.rb +5 -0
  62. data/lib/xbrlware/taxonomy.rb +7 -0
  63. data/lib/xbrlware/unit.rb +1 -0
  64. data/lib/xbrlware/version.rb +1 -1
  65. data/lib/xbrlware/xml_parser.rb +20 -0
  66. data/test/lib/edgar/edgar_data_downloader_test.rb +1 -1
  67. data/test/lib/edgar/resources/usgaap.rss.xml +3914 -2599
  68. data/test/lib/xbrlware/46_item_test.rb +30 -0
  69. data/test/lib/xbrlware/47_context_test.rb +16 -8
  70. data/test/lib/xbrlware/48_unit_test.rb +10 -0
  71. data/test/lib/xbrlware/instance_test.rb +156 -2
  72. data/test/lib/xbrlware/linkbase/calculation_linkbase_test.rb +5 -5
  73. data/test/lib/xbrlware/linkbase/definition_linkbase_test.rb +2 -2
  74. data/test/lib/xbrlware/linkbase/presentation_linkbase_test.rb +0 -1
  75. data/test/lib/xbrlware/taxonomy_test.rb +28 -0
  76. data/test/lib/xbrlware/xml_parser_test.rb +81 -0
  77. data/test/scratchpad/tooltip.html +10 -0
  78. data/xbrlware-ce.gemspec +2 -0
  79. metadata +36 -22
  80. data/Rakefile.rb +0 -124
  81. data/doc/classes/Xbrlware/Report.html +0 -352
  82. data/lib/xbrlware/report.rb +0 -277
  83. data/test/lib/xbrlware/resources/report_test_xbrl_files/cal.xml +0 -219
  84. data/test/lib/xbrlware/resources/report_test_xbrl_files/def.xml +0 -186
  85. data/test/lib/xbrlware/resources/report_test_xbrl_files/instance.xml +0 -5822
  86. data/test/lib/xbrlware/resources/report_test_xbrl_files/lab.xml +0 -782
  87. data/test/lib/xbrlware/resources/report_test_xbrl_files/pre.xml +0 -485
  88. data/test/lib/xbrlware/resources/report_test_xbrl_files/report/report_index.html +0 -62
  89. data/test/lib/xbrlware/resources/report_test_xbrl_files/taxonomy.xsd +0 -178
  90. data/xbrlware.iml +0 -30
@@ -0,0 +1,62 @@
1
+ require 'xbrlware'
2
+
3
+ ## Assuming you have table "calculations" with below structure
4
+ # id
5
+ # element_name
6
+ # element_value
7
+ # element_label
8
+ # period_start_date
9
+ # period_end_date
10
+ # parent_id
11
+
12
+ def format_timeline(timeline) ## date format function
13
+ return Xbrlware::DateUtil.stringify_date(timeline.value) unless timeline.is_duration?
14
+ header = StringIO.new
15
+ header << Xbrlware::DateUtil.stringify_date(timeline.value["end_date"]) << " : "
16
+ header << Xbrlware::DateUtil.months_between(timeline.value["start_date"], timeline.value["end_date"]).to_s
17
+ header << " months ( from " << Xbrlware::DateUtil.stringify_date(timeline.value["start_date"]) << ")"
18
+ header.string
19
+ end
20
+
21
+ def to_table(cal_elements, timeline, parent=nil)
22
+ cal_elements.each do |element|
23
+
24
+ id="table_unique_id_or_primary_key" # replace this with db unique-id.
25
+ p_element_id=id if parent.nil?
26
+ p_element_id=parent unless parent.nil?
27
+
28
+ matched_item=element.items.select {|item| timeline.to_s==item.context.period.to_s}[0]
29
+
30
+ unless matched_item.nil?
31
+ ### to calculation table
32
+
33
+ element_label = element.label
34
+ element_name=matched_item.name
35
+ element_value=matched_item.value
36
+
37
+ period = matched_item.context.period
38
+ period_start_date, period_end_date = period.value["start_date"], period.value["end_date"] if period.is_duration?
39
+ period_start_date, period_end_date = period.value, period.value if period.is_instant?
40
+ period_start_date, period_end_date = nil, nil if period.is_forever?
41
+
42
+ parent_id = p_element_id
43
+
44
+ # Insert to table
45
+ end
46
+ to_table(element.children, timeline, id) if element.has_children?
47
+ end
48
+ end
49
+
50
+ ins=Xbrlware.ins("/data/764180/000119312510039027/mo-20091231.xml") # change this with actual instance files
51
+ cals=ins.taxonomy.callb.calculation
52
+
53
+ cals.each do |cal|
54
+ puts"\n\n Start ::: Calculation -- #{cal.title} \n\n"
55
+ cal.timelines.each do |timeline|
56
+ puts"#{format_timeline(timeline)}"
57
+ to_table(cal.arcs, timeline)
58
+ puts "\n"
59
+ end
60
+ puts" End ::: Calculation -- #{cal.title}"
61
+ puts "=" * 80
62
+ end
@@ -0,0 +1,27 @@
1
+ require 'edgar'
2
+ require 'xbrlware'
3
+
4
+ d=Edgar::HTMLFeedDownloader.new
5
+ url="http://www.sec.gov/Archives/edgar/data/1281761/000119312510036446/0001193125-10-036446-index.htm"
6
+ download_dir=url.split("/")[-2] # download dir is : 000119312510036446
7
+ d.download(url, download_dir)
8
+
9
+ ins=Xbrlware.ins(Xbrlware.file_grep(download_dir)["ins"])
10
+ fye=ins.entity_details["fiscal_end_date"]
11
+
12
+ data={}
13
+ [2009, 2008].each do |year|
14
+ end_date=Date.parse(fye.gsub(/--/, "#{year}-"))
15
+ items=ins.item_ctx_filter("CashAndCashEquivalentsAtCarryingValue") do |ctx|
16
+ day_diff=(ctx.period.value-end_date).to_i
17
+ ctx.period.is_instant? && (day_diff==0 || day_diff==1)
18
+ end
19
+ data[year]=items[0]
20
+ end
21
+
22
+ cash_2008=data[2008].value
23
+ cash_2009=data[2009].value
24
+
25
+ puts "Percentage increase/decrease in cash value 2008-2009 is === #{((cash_2009.to_f-cash_2008.to_f)/cash_2008.to_f) * 100}"
26
+
27
+
@@ -45,8 +45,8 @@ module Edgar
45
45
  data_dir=data_dir+File::SEPARATOR+item["xbrlFiling"][0]["accessionNumber"][0]["content"]
46
46
  mkdir(data_dir)
47
47
  files.each do |file|
48
- file_content=open(file["url"]).read
49
- dump_to_file(data_dir+File::SEPARATOR+file["file"], file_content)
48
+ file_content=open(file["edgar:url"]).read
49
+ dump_to_file(data_dir+File::SEPARATOR+file["edgar:file"], file_content)
50
50
  end
51
51
  end
52
52
  end
@@ -60,9 +60,9 @@ module Edgar
60
60
  files=get_xbrl_files(item)
61
61
  files.each do |file|
62
62
  if file["type"]=="EX-101.INS" && (i_size==0 || file["size"].to_i < i_size)
63
- i_size = file["size"].to_i
64
- i_url = file["url"]
65
- title = item["title"]
63
+ i_size = file["edgar:size"].to_i
64
+ i_url = file["edgar:url"]
65
+ title = item["edgar:title"]
66
66
  end
67
67
  end
68
68
  end
@@ -74,7 +74,7 @@ module Edgar
74
74
  # Gets url that end with xml and xsd
75
75
  def get_xbrl_files(item)
76
76
  xbrl_files=item["xbrlFiling"][0]["xbrlFiles"][0]["xbrlFile"]
77
- return xbrl_files.select {|e| e["url"].end_with?("xml") || e["url"].end_with?("xsd")}
77
+ return xbrl_files.select {|e| e["edgar:url"].end_with?("xml") || e["edgar:url"].end_with?("xsd")}
78
78
  end
79
79
 
80
80
  end
data/lib/xbrlware.rb CHANGED
@@ -28,6 +28,7 @@ require 'set'
28
28
  require "stringio"
29
29
  require 'cgi'
30
30
 
31
+ require 'xbrlware/version'
31
32
  require 'xbrlware/float_patch'
32
33
  require 'xbrlware/cgi_patch'
33
34
  require 'xbrlware/meta_util'
@@ -41,6 +42,7 @@ require 'xbrlware/util'
41
42
  require 'xbrlware/taxonomies/us_gaap_taxonomy_20090131'
42
43
  require 'xbrlware/taxonomy'
43
44
 
45
+ require 'xbrlware/ns_aware'
44
46
  require 'xbrlware/context'
45
47
  require 'xbrlware/instance'
46
48
  require 'xbrlware/unit'
@@ -21,6 +21,8 @@ module Xbrlware
21
21
  # This class represents each context in the XBRL instance file.
22
22
  # Look at {delaing with instance page on xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/InstanceTaxonomy] for more details.
23
23
  class Context
24
+ include NSAware
25
+
24
26
  attr_reader :id, :entity, :period, :scenario
25
27
  PERIOD_FOREVER = -1
26
28
 
@@ -28,7 +28,7 @@ module Xbrlware
28
28
 
29
29
  # Creates an Instance.
30
30
  #
31
- # instance_filepath:: XBRL Instance source. Tries to load and parse instance file from the path.
31
+ # instance_str:: XBRL Instance source. Tries to load and parse instance file from the instance_str. This can be XBRL instance file from the file system or XBRL content string.
32
32
  #
33
33
  # taxonomy_filepath::
34
34
  # optional parameter, XBRL Taxonomy source. Tries to load and parse taxonomy file from path.
@@ -39,21 +39,28 @@ module Xbrlware
39
39
  # which will cause parsing error. Hence any exceptions during instance source parsing, will trigger re-parsing of
40
40
  # the entire instnace file with new lines replaced.
41
41
  # Look at {delaing with instance page on xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/InstanceTaxonomy] for details.
42
- def initialize(instance_filepath, taxonomy_filepath=nil)
42
+ def initialize(instance_str, taxonomy_filepath=nil)
43
43
  m=Benchmark.measure do
44
44
  begin
45
- @file_name=instance_filepath
46
- @xbrl_content = XmlParser.xml_in(instance_filepath, {'ForceContent' => true})
45
+ @file_name=instance_str unless instance_str =~ /<.*?>/m
46
+ @xbrl_content = XmlParser.xml_in(instance_str, {'ForceContent' => true})
47
47
  rescue Exception
48
- $LOG.warn "File ["+instance_filepath+"] is not well formed. Starting reparsing after removing new lines."
49
- @xbrl_content = XmlParser.xml_in(File.open(instance_filepath).read.gsub("\n", ""), {'ForceContent' => true})
48
+ new_content=nil
49
+ if instance_str =~ /<.*?>/m
50
+ $LOG.warn "Supplied XBRL content is not well formed. Starting reparsing after removing new lines."
51
+ new_content=instance_str.gsub("\n", "")
52
+ else
53
+ $LOG.warn "File ["+instance_str+"] is not well formed. Starting reparsing after removing new lines."
54
+ new_content=File.open(instance_str).read.gsub("\n", "")
55
+ end
56
+ @xbrl_content = XmlParser.xml_in(new_content, {'ForceContent' => true}) unless new_content.nil?
50
57
  end
51
58
  end
52
- bm("Parsing [" + instance_filepath + "] took", m)
59
+ bm("Parsing [" + instance_str + "] took", m)
53
60
 
54
61
  # if taxonomy file is not supplied, get it from instance schema_ref
55
62
  if taxonomy_filepath.nil?
56
- taxonomy_file_location=File.dirname(instance_filepath)+File::Separator+schema_ref
63
+ taxonomy_file_location=File.dirname(instance_str)+File::Separator+schema_ref
57
64
  taxonomy_filepath = taxonomy_file_location if File.exist?(taxonomy_file_location) && (not File.directory?(taxonomy_file_location))
58
65
  end
59
66
 
@@ -131,8 +138,8 @@ module Xbrlware
131
138
  all_contexts= context(nil, dimensions)
132
139
  all_contexts=[all_contexts] unless all_contexts.is_a?(Array)
133
140
  all_contexts.each do |ctx|
134
- period_group[ctx.period.to_s] = [] if period_group[ctx.period.to_s].nil?
135
- period_group[ctx.period.to_s] << ctx
141
+ period_group[ctx.period] = [] if period_group[ctx.period].nil?
142
+ period_group[ctx.period] << ctx
136
143
  end
137
144
  period_group
138
145
  end
@@ -152,6 +159,10 @@ module Xbrlware
152
159
  end
153
160
  end
154
161
 
162
+ def inspect
163
+ self.to_s
164
+ end
165
+
155
166
  private
156
167
  # Takes optional context_id
157
168
  # Returns all contexts if context_id is nil
@@ -183,7 +194,10 @@ module Xbrlware
183
194
  p = period(period_content)
184
195
 
185
196
  s = scenario(ctx_content)
186
- return Context.new(id, e, p, s)
197
+ _context = Context.new(id, e, p, s)
198
+ _context.ns=ctx_content["nspace"]
199
+ _context.nsp=ctx_content["nspace_prefix"]
200
+ return _context
187
201
  end
188
202
 
189
203
  # Returns map if period is duration. Map has key with name "start_date" and "end_date"
@@ -237,8 +251,9 @@ module Xbrlware
237
251
 
238
252
  next unless unit_id.nil? || unit["id"].to_s == unit_id
239
253
 
254
+ _unit=nil
240
255
  unless unit["measure"].nil?
241
- units << Unit.new(unit["id"], l.call(unit["measure"]))
256
+ _unit = Unit.new(unit["id"], l.call(unit["measure"]))
242
257
  else
243
258
  divide_content = unit["divide"][0]
244
259
 
@@ -246,8 +261,11 @@ module Xbrlware
246
261
  denominator = l.call(divide_content["unitDenominator"][0]["measure"])
247
262
 
248
263
  divide=Unit::Divide.new(numerator, denominator)
249
- units << Unit.new(unit["id"], divide)
264
+ _unit = Unit.new(unit["id"], divide)
250
265
  end
266
+ _unit.ns=unit["nspace"]
267
+ _unit.nsp=unit["nspace_prefix"]
268
+ units << _unit
251
269
  end
252
270
  return units[0] unless unit_id.nil?
253
271
  units
@@ -265,22 +283,41 @@ module Xbrlware
265
283
  decimals = item["decimals"] unless item["decimals"].nil?
266
284
 
267
285
  _footnotes = footnotes(item["id"]) unless item["id"].nil?
268
- item=Item.new(name, context, value, unit, precision, decimals, _footnotes)
269
- item.def=@taxonomy.definition(name)
270
- return item
286
+ _item=Item.new(self, name, context, value, unit, precision, decimals, _footnotes)
287
+ _item.ns=item["nspace"]
288
+ _item.nsp=item["nspace_prefix"]
289
+ _item.def=@taxonomy.definition(name)
290
+ return _item
271
291
  end
272
292
 
273
293
  public
274
- def item_all_map
294
+ def item_all
295
+
296
+ return @item_all unless @item_all.nil?
297
+
275
298
  all_items = @xbrl_content
276
299
  return nil if all_items.nil?
277
300
 
278
- items_hash={}
301
+ @item_all=[]
279
302
 
280
303
  all_items.each do |name, item_content|
281
- _name=name.upcase
282
- next if _name=="CONTEXT" || _name=="UNIT"
283
- items_hash[name.upcase] = item(name)
304
+ next unless item_content.is_a?(Array)
305
+ next if item_content.size > 0 && item_content[0]["contextRef"].nil?
306
+ @item_all = @item_all + item(name)
307
+ end
308
+ @item_all
309
+ end
310
+
311
+ def item_all_map
312
+ items=item_all
313
+ return nil if items.nil?
314
+
315
+ items_hash={}
316
+
317
+ items.each do |item|
318
+ _name= item.name.upcase
319
+ items_hash[_name] = [] unless items_hash.include?(_name)
320
+ items_hash[_name] << item
284
321
  end
285
322
  items_hash
286
323
  end
@@ -292,7 +329,7 @@ module Xbrlware
292
329
 
293
330
  item_content = @xbrl_content[name]
294
331
 
295
- return nil if item_content.nil?
332
+ return [] if item_content.nil?
296
333
 
297
334
  items=[]
298
335
 
@@ -375,11 +412,13 @@ module Xbrlware
375
412
  @entity_details["fiscal_end_date"]=e_fiscal_end_date.value unless e_fiscal_end_date.nil?
376
413
  @entity_details["common_shares_outstanding"]=e_common_shares_outstanding.value unless e_common_shares_outstanding.nil?
377
414
 
378
- file_name=File.basename(@file_name)
379
- symbol=file_name.split("-")[0]
380
- symbol.upcase!
415
+ unless @file_name.nil?
416
+ file_name=File.basename(@file_name)
417
+ symbol=file_name.split("-")[0]
418
+ symbol.upcase!
381
419
 
382
- @entity_details["symbol"]=symbol unless symbol.nil?
420
+ @entity_details["symbol"]=symbol unless symbol.nil?
421
+ end
383
422
  rescue Exception => e
384
423
  @entity_details
385
424
  end
data/lib/xbrlware/item.rb CHANGED
@@ -23,12 +23,15 @@ module Xbrlware
23
23
  # Taxonomy definition of a item can be retrieved using def or meta methods.
24
24
  # Look at {delaing with instance page on xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/InstanceTaxonomy] for more details.
25
25
  class Item
26
- attr_reader :name, :context,:unit,:precision,:decimals, :footnotes
27
- attr_accessor :def
26
+ include NSAware
27
+
28
+ attr_reader :name, :context, :unit, :precision, :decimals, :footnotes
29
+ attr_accessor :ins, :def
28
30
 
29
31
  # Constructs item
30
32
  # value is normalized based on precision and decimals passed as per XBRL specification
31
- def initialize(name, context, value, unit=nil,precision=nil,decimals=nil, footnotes=nil)
33
+ def initialize(instance, name, context, value, unit=nil, precision=nil, decimals=nil, footnotes=nil)
34
+ @ins=instance
32
35
  @name=name
33
36
  @context = context
34
37
  @precision=precision
@@ -39,10 +42,14 @@ module Xbrlware
39
42
  end
40
43
 
41
44
  def value
42
- return yield(@value) if block_given?
45
+ return yield(@value) if block_given?
43
46
  @value
44
47
  end
45
-
48
+
49
+ def is_value_numeric?
50
+ @value.to_i.to_s == @value || @value.to_f.to_s == @value
51
+ end
52
+
46
53
  alias_method :meta, :def
47
54
 
48
55
  def balance
@@ -51,40 +58,40 @@ module Xbrlware
51
58
  end
52
59
 
53
60
  class ItemValue # :nodoc:
54
-
61
+
55
62
  attr_reader :item_value
56
-
57
- def initialize(item_value,precision=nil,decimals=nil)
63
+
64
+ def initialize(item_value, precision=nil, decimals=nil)
58
65
  @item_value=item_value
59
66
  @precision=precision
60
67
  @decimals=decimals
61
68
  end
62
69
 
63
70
  def value()
64
- return precision() unless @precision.nil?
71
+ return precision() unless @precision.nil?
65
72
  return decimals() unless @decimals.nil?
66
73
  return @item_value
67
74
  end
68
-
75
+
69
76
  # returns BigDecimal float representation as String
70
77
  def precision()
71
78
  return @item_value if @precision=="INF"
72
-
79
+
73
80
  precision_i=@precision.to_i
74
81
  new_value=BigDecimal(@item_value)
75
-
82
+
76
83
  is_value_integer = new_value==@item_value.to_i
77
-
78
-
79
- return to_precision_from_integer(@item_value.to_i, precision_i) if is_value_integer
80
-
84
+
85
+
86
+ return to_precision_from_integer(@item_value.to_i, precision_i) if is_value_integer
87
+
81
88
  index_of_dot = new_value.abs.to_s("F").index(".")
82
-
89
+
83
90
  # When mod value is greater than 1 and float number
84
91
  if new_value.abs > 1
85
92
  #Precision is less than number of digits before decimal
86
93
  return to_precision_from_integer(new_value.to_i, precision_i) if precision_i <= index_of_dot
87
-
94
+
88
95
  #Precision is greater than number of digits before decimal
89
96
  return new_value.round(precision_i-index_of_dot).to_s("F")
90
97
  else
@@ -93,23 +100,24 @@ module Xbrlware
93
100
  return new_value.round(no_of_zeroes + precision_i).to_s("F")
94
101
  end
95
102
  end
96
-
103
+
97
104
  # returns BigDecimal float representation as String
98
105
  def decimals
99
- return BigDecimal(@item_value).round(@decimals.to_i).to_s("F")
106
+ return @item_value if @decimals=="INF"
107
+ return BigDecimal(@item_value).round(@decimals.to_i).to_s("F")
100
108
  end
101
-
102
- private
109
+
110
+ private
103
111
  def to_precision_from_integer(new_value, precision_i)
104
112
  factor=10 **(new_value.abs.to_s.length - precision_i)
105
113
  return to_big_decimal_float_str(((BigDecimal(new_value.to_s) / factor).to_i * factor).to_s)
106
114
  end
107
-
115
+
108
116
  def to_big_decimal_float_str(value)
109
117
  return BigDecimal(value).to_s("F")
110
118
  end
111
-
119
+
112
120
  end
113
- end
114
-
121
+ end
122
+
115
123
  end