Sha256: 0bf3d10ad85162390ba26fcae6b7e1407db088c17d93b128992f253087b52e9a

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

require 'marc_extensions'

module BerkeleyLibrary
  module TIND
    module Export
      class Column

        # @return [ColumnGroup] the group containing this column
        attr_reader :column_group

        # @return [Integer] the index of this column in the group
        attr_reader :col_in_group

        # Initializes a new column
        #
        # @param column_group [ColumnGroup] the group containing this column
        # @param col_in_group [Integer] the index of this column in the group
        def initialize(column_group, col_in_group)
          @column_group = column_group
          @col_in_group = col_in_group
        end

        def header
          # NOTE: that TIND "-#" suffixes must be unique by tag, not tag + ind1 + ind2
          @header ||= "#{column_group.prefix}#{subfield_code}-#{1 + column_group.index_in_tag}"
        end

        def subfield_code
          @subfield_code ||= column_group.subfield_codes[col_in_group]
        end

        def value_at(row)
          column_group.value_at(row, col_in_group)
        end

        def can_edit?
          @can_edit ||= Filter.can_edit?(
            column_group.tag,
            column_group.ind1,
            column_group.ind2,
            subfield_code
          )
        end

        def each_value(include_header: false)
          return to_enum(:each_value, include_header: include_header) unless block_given?

          yield header if include_header
          column_group.row_count.times { |row| yield value_at(row) }
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
berkeley_library-tind-0.7.2 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.7.1 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.7.0 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.6.0 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.5.1 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.5.0 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.4.3 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.4.2 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.4.1 lib/berkeley_library/tind/export/column.rb
berkeley_library-tind-0.4.0 lib/berkeley_library/tind/export/column.rb