Class: Json2::Header
- Inherits:
-
Object
- Object
- Json2::Header
- Defined in:
- lib/json2/header.rb
Overview
Build a csv header.
Class Method Summary collapse
-
.get(keys) ⇒ Object
Get the header of a Csv file.
Instance Method Summary collapse
-
#get ⇒ Object
Get the header of a Csv file.
-
#initialize(keys) ⇒ Header
constructor
Creates a new Header instance.
Constructor Details
#initialize(keys) ⇒ Header
Creates a new Header instance.
keys - A Hash of String names of variable/column.
19 20 21 22 |
# File 'lib/json2/header.rb', line 19 def initialize(keys) @header = [] @keys = keys end |
Class Method Details
.get(keys) ⇒ Object
Get the header of a Csv file.
For a description of the parameter(s) see Header#initialize.
Returns the String header, that is a single line with comma separated column’s name.
12 13 14 |
# File 'lib/json2/header.rb', line 12 def self.get(keys) new(keys).get end |
Instance Method Details
#get ⇒ Object
Get the header of a Csv file. See also Header.get.
Returns the String header.
27 28 29 30 31 32 33 |
# File 'lib/json2/header.rb', line 27 def get @keys.each do |key| short_name = key.split('.').last @header << (@header.include?(short_name) ? key : short_name) end @header.join(',') + "\n" end |