Sha256: 2ea1e18cf439f36eab17a812effe92bcca9fb0dc7895e0229a8ed530ffd650da

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'litexbrl/tdnet/account_item'
require 'litexbrl/tdnet/summary_attribute'
require 'litexbrl/tdnet/results_forecast_attribute'
require 'litexbrl/tdnet/company_attribute'
require 'litexbrl/tdnet/financial_information'
require 'litexbrl/tdnet/summary'
require 'litexbrl/tdnet/results_forecast'
require 'litexbrl/tdnet/financial_information2'
require 'litexbrl/tdnet/summary2'
require 'litexbrl/tdnet/results_forecast2'
require 'litexbrl/tdnet/cash_flow2'

module LiteXBRL
  module TDnet

    class << self

      def parse(path)
        doc = File.open(path) {|f| Nokogiri::XML f }
        read doc
      end

      def parse_string(str)
        doc = Nokogiri::XML str
        read doc
      end

      def parse_cash_flow(str)
        doc = Nokogiri::XML str
        CashFlow2.read doc
      end

      private

      def read(doc)
        document = find_reader doc

        document.read doc
      end

      def find_reader(doc)
        namespaces = doc.namespaces

        # TODO 委嬢する?
        if summary? namespaces
          Summary
        elsif summary2? namespaces
          Summary2
        elsif results_forecast? namespaces
          ResultsForecast
        elsif results_forecast2? namespaces
          ResultsForecast2
        else
          raise StandardError.new "ドキュメントがありません"
        end
      end

      def summary?(namespaces)
        namespaces.keys.any? {|ns| /tdnet-.+(jpsm|ussm|ifsm)/ =~ ns }
      end

      def summary2?(namespaces)
        namespaces.keys.any? {|ns| /tse-.+(jpsm|ussm|ifsm|jpsy|ussy|ifsy)/ =~ ns }
      end

      def results_forecast?(namespaces)
        namespaces.keys.any? {|ns| /tdnet-rvfc/ =~ ns }
      end

      def results_forecast2?(namespaces)
        namespaces.keys.any? {|ns| /tse-rvfc/ =~ ns }
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
litexbrl-0.2.2 lib/litexbrl/tdnet.rb