# statement.rb

module SecStatementParser

  class Statement
    include SecStatementFields
    include Debug


    attr_reader(:symbol,:urls)

    @@single_mapping_fields.each do |k, v|
      self.__send__(:attr_reader, k)
    end

    def initialize(log_level='')
      init_logger(log_level)
    end

    def list(symbol='')
      puts "Please enter symbol." or return nil if symbol.empty?

      @list = StatementUrlList.get(symbol.upcase)
    end

    def parse_annual_report(year)
      # Check year range
      return nil unless year_range_is_valid(year)

      # TODO: reset fields before parse

      link = @urls[:annual_report]["y#{year}".to_sym]
      result = SecStatementFields.parse(link)

      # Set parsed results to instance variables of Statement
      result.each do |k, v|
        instance_variable_set("@#{k}", v)
      end

      return result
    end

    def parse_link(link)
      result = SecStatementFields.parse(link)
      return result
    end

    def parse_file(file)
      return nil unless file.is_a? File
      result = SecStatementFields.parse(file)

      # Set parsed results to instance variables of Statement
      result.each do |k, v|
        instance_variable_set("@#{k}", v)
      end

      return result
    end
  end
end

# statement.rb

module SecStatementParser

  class Statement
    include SecStatementFields
    include Debug


    attr_reader(:symbol,:urls)

    @@single_mapping_fields.each do |k, v|
      self.__send__(:attr_reader, k)
    end

    def initialize(log_level='')
      init_logger(log_level)
    end

    def list(symbol='')
      puts "Please enter symbol." or return nil if symbol.empty?

      @list = StatementUrlList.get(symbol.upcase)
    end

    def parse_annual_report(year)
      # Check year range
      return nil unless year_range_is_valid(year)

      # TODO: reset fields before parse

      link = @urls[:annual_report]["y#{year}".to_sym]
      result = SecStatementFields.parse(link)

      # Set parsed results to instance variables of Statement
      result.each do |k, v|
        instance_variable_set("@#{k}", v)
      end

      return result
    end

    def parse_link(link)
      result = SecStatementFields.parse(link)

      # Set parsed results to instance variables of Statement
      result.each do |k, v|
        instance_variable_set("@#{k}", v)
      end

      return result
    end

    def parse_file(file)
      return nil unless file.is_a? File
      result = SecStatementFields.parse(file)

      # Set parsed results to instance variables of Statement
      result.each do |k, v|
        instance_variable_set("@#{k}", v)
      end

      return result
    end
  end
end

Set parsed results to instance variables of Statement in parse_link()
Set parsed results to instance variables of Statement in parse_link()
