class AccessibleSeedYaml::Record
This class is wrapper of seed for one record.
Functions: - Fetch seed attributes by hash. - Stored original seed string. It can fetch anytime.
Attributes
original_seed[R]
Public Class Methods
new(seed_for_one_record)
click to toggle source
@param [String] seed_for_one_record seed string for one record. @raise [ArgumentError] if argument has not only one key then raise. @example
<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.
# 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
Public Instance Methods
attributes()
click to toggle source
@return [Hash] attributes of seed data by hash. @example
<source> data1: id: 1 name: "one" <return> {"id" => 1, "name" => "one"}
# File lib/accessible_seed_yaml/record.rb, line 46 def attributes @seed_data_by_hash.values.first end
key()
click to toggle source
@return [String] record key @example
<source> data1: id: 1 name: "one" <return> "data1"
# File lib/accessible_seed_yaml/record.rb, line 59 def key @seed_data_by_hash.keys.first end
to_s()
click to toggle source
@return [String] this record data by yaml string @example
<source> "data1:\n id: 1\n name: "one" <return> "data1:\n id: 1\n name: "one"
# File lib/accessible_seed_yaml/record.rb, line 70 def to_s self.original_seed end
Private Instance Methods
exchange_to_hash()
click to toggle source
# File lib/accessible_seed_yaml/record.rb, line 76 def exchange_to_hash @seed_data_by_hash ||= YAML.load(@original_seed) unless @seed_data_by_hash.size == 1 raise ArgumentError.new('original_seed key size is not 1.') end end