Class: Linkage::Group

Inherits:
Object
  • Object
show all
Includes:
Decollation
Defined in:
lib/linkage/group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Decollation

#decollate, #decollate_mysql, #decollate_mysql_latin1_swedish_ci

Constructor Details

#initialize(values, options) ⇒ Group

Returns a new instance of Group.

Examples:

Linkage::Group.new({:foo => 123, :bar => 'baz'}, {:count => 5, :id => 456})

Parameters:

  • values (Hash)

    Values that define this group

  • options (Hash)

Options Hash (options):

  • :id (Fixnum)

    The group ID

  • :count (Fixnum)

    How many records are in the group

  • :ruby_types (Hash)

    Hash of ruby types for each value

  • :database_type (Symbol)


35
36
37
38
39
40
41
# File 'lib/linkage/group.rb', line 35

def initialize(values, options)
  @count = options[:count]
  @id = options[:id]
  @ruby_types = options[:ruby_types]
  @database_type = options[:database_type]
  @values = values
end

Instance Attribute Details

#countInteger (readonly)

Returns Number of records in this group.

Returns:

  • (Integer)

    Number of records in this group



9
10
11
# File 'lib/linkage/group.rb', line 9

def count
  @count
end

#idInteger (readonly)

Returns This group’s ID (if it exists).

Returns:

  • (Integer)

    This group’s ID (if it exists)



12
13
14
# File 'lib/linkage/group.rb', line 12

def id
  @id
end

#valuesHash (readonly)

Returns Hash of matching values.

Returns:

  • (Hash)

    Hash of matching values



6
7
8
# File 'lib/linkage/group.rb', line 6

def values
  @values
end

Class Method Details

.from_row(row) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/linkage/group.rb', line 14

def self.from_row(row)
  values = {}
  options = {}
  row.each_pair do |key, value|
    if key == :id || key == :count
      options[key] = value
    else
      values[key] = value
    end
  end
  new(values, options)
end

Instance Method Details

#decollated_valuesObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/linkage/group.rb', line 43

def decollated_values
  @values.inject({}) do |hsh, (key, value)|
    ruby_type = @ruby_types[key]
    if ruby_type && ruby_type.has_key?(:opts) && ruby_type[:opts].has_key?(:collate)
      hsh[key] = decollate(value, @database_type, ruby_type[:opts][:collate])
    else
      hsh[key] = value
    end
    hsh
  end
end