Class: AccessibleSeedYaml::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/accessible_seed_yaml/record.rb

Overview

This class is wrapper of seed for one record.

Functions:
 - Fetch seed attributes by hash.
 - Stored original seed string. It can fetch anytime.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed_for_one_record) ⇒ Record

Returns a new instance of Record.

Examples:

<Correct>
````
data1:
  id: 1
  name: "one"
````
 => this is one record.

<Wrong>
````
data1:
  id: 1
  name: "one"
data2:
  id: 2
  name: "two"
````
 => this is tow record.

Parameters:

  • seed_for_one_record (String)

    seed string for one record.

Raises:

  • (ArgumentError)

    if argument has not only one key then raise.



32
33
34
35
# File 'lib/accessible_seed_yaml/record.rb', line 32

def initialize(seed_for_one_record)
  @original_seed = seed_for_one_record
  exchange_to_hash
end

Instance Attribute Details

#original_seedObject (readonly)

Returns the value of attribute original_seed.



8
9
10
# File 'lib/accessible_seed_yaml/record.rb', line 8

def original_seed
  @original_seed
end

Instance Method Details

#attributesHash

Returns attributes of seed data by hash.

Examples:

<source>
data1:
  id: 1
  name: "one"

<return>
{"id" => 1, "name" => "one"}

Returns:

  • (Hash)

    attributes of seed data by hash.



46
47
48
# File 'lib/accessible_seed_yaml/record.rb', line 46

def attributes
  @seed_data_by_hash.values.first
end

#keyString

Returns record key.

Examples:

<source>
data1:
  id: 1
  name: "one"

<return>
"data1"

Returns:

  • (String)

    record key



59
60
61
# File 'lib/accessible_seed_yaml/record.rb', line 59

def key
  @seed_data_by_hash.keys.first
end

#to_sString

Returns this record data by yaml string.

Examples:

<source>
"data1:\n  id: 1\n  name: "one"

<return>
"data1:\n  id: 1\n  name: "one"

Returns:

  • (String)

    this record data by yaml string



70
71
72
# File 'lib/accessible_seed_yaml/record.rb', line 70

def to_s
  self.original_seed
end