Sha256: 2abb2e96aac03e521855513571f7aae6887643b2f088cf8b12462b7e662ecdf8

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 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'

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

      private

      def read(doc)
        document = find_document doc

        document.read doc
      end

      def find_document(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)/ =~ 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

5 entries across 5 versions & 1 rubygems

Version Path
litexbrl-0.1.3 lib/litexbrl/tdnet.rb
litexbrl-0.1.2 lib/litexbrl/tdnet.rb
litexbrl-0.1.1 lib/litexbrl/tdnet.rb
litexbrl-0.1.0 lib/litexbrl/tdnet.rb
litexbrl-0.0.3 lib/litexbrl/tdnet.rb