Class: Spread2RDF::Coord

Inherits:
Struct
  • Object
show all
Defined in:
lib/spread2rdf/coord.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Coord

Returns a new instance of Coord.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/spread2rdf/coord.rb', line 3

def initialize(*args)
  case args.length
    when 2 then super
    when 1
      case args = args.first
        when Hash
          super(args[:column], args[:row])
        when Symbol, String
          coord = args.to_s
          raise "Invalid cell coordinates #{coord}" unless coord =~ /([A-Za-z]+)(\d+)/
          super(Regexp.last_match[1], Regexp.last_match[2].to_i)
        else raise ArgumentError, "can't handle argument #{args}"
      end
    else raise ArgumentError, "too many arguments: #{args}"
  end
end

Instance Attribute Details

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



2
3
4
# File 'lib/spread2rdf/coord.rb', line 2

def column
  @column
end

#rowObject

Returns the value of attribute row

Returns:

  • (Object)

    the current value of row



2
3
4
# File 'lib/spread2rdf/coord.rb', line 2

def row
  @row
end

Class Method Details

.increment_column(column, count = 1) ⇒ Object



43
44
45
# File 'lib/spread2rdf/coord.rb', line 43

def increment_column(column, count=1)
  Roo::Base.number_to_letter(Roo::Base.letter_to_number(column) + count)
end

Instance Method Details

#column_as_indexObject



24
25
26
# File 'lib/spread2rdf/coord.rb', line 24

def column_as_index
  column_as_number - 1
end

#column_as_numberObject



20
21
22
# File 'lib/spread2rdf/coord.rb', line 20

def column_as_number
  Roo::Base.letter_to_number(column)
end

#increment_column(count = 1) ⇒ Object



28
29
30
# File 'lib/spread2rdf/coord.rb', line 28

def increment_column(count = 1)
  self.class.increment_column(self.column, count)
end

#to_sObject



32
33
34
# File 'lib/spread2rdf/coord.rb', line 32

def to_s
  "#{column}#{row}"
end

#to_symObject



36
37
38
# File 'lib/spread2rdf/coord.rb', line 36

def to_sym
  to_s.to_sym
end