Class: CustomTracker::Entry
- Inherits:
-
Object
- Object
- CustomTracker::Entry
- Includes:
- Enumerable
- Defined in:
- lib/custom_tracker/entry.rb
Overview
Single tracker entry.
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
Id of entry.
-
#time ⇒ Time
readonly
Time of entry creation.
Instance Method Summary collapse
-
#[](sym) ⇒ Object
Data from entry.
-
#columns ⇒ Array<Symbols>
Array of column names.
-
#each {|key, value| ... } ⇒ self
Calls the given block once for each pair in data.
-
#has?(sym) ⇒ Boolean
Whether entry stores this column.
-
#initialize(data) ⇒ Entry
constructor
Creates new entry.
-
#to_s ⇒ String
Human-readable string.
Constructor Details
#initialize(data) ⇒ Entry
Creates new entry.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/custom_tracker/entry.rb', line 61 def initialize(data) @time = Time.now @time.freeze # Generating id from current time and random suffix @id = (@time.to_i * 65536 + rand(65536)).to_s(16) @id.freeze @data = {} data.each_pair do |key, value| next unless key.is_a? Symbol @data[key] = value end @data.freeze end |
Instance Attribute Details
#id ⇒ String (readonly)
Returns id of entry.
25 26 27 |
# File 'lib/custom_tracker/entry.rb', line 25 def id @id end |
#time ⇒ Time (readonly)
Returns time of entry creation.
21 22 23 |
# File 'lib/custom_tracker/entry.rb', line 21 def time @time end |
Instance Method Details
#[](sym) ⇒ Object
Returns data from entry.
37 38 39 |
# File 'lib/custom_tracker/entry.rb', line 37 def [](sym) @data[sym] end |
#columns ⇒ Array<Symbols>
Returns Array of column names.
29 30 31 |
# File 'lib/custom_tracker/entry.rb', line 29 def columns @data.keys end |
#each {|key, value| ... } ⇒ self
Calls the given block once for each pair in data.
15 16 17 |
# File 'lib/custom_tracker/entry.rb', line 15 def each(&block) @data.each &block end |
#has?(sym) ⇒ Boolean
Returns whether entry stores this column.
45 46 47 |
# File 'lib/custom_tracker/entry.rb', line 45 def has?(sym) @data.has_key?(sym) end |
#to_s ⇒ String
Returns human-readable string.
51 52 53 54 55 |
# File 'lib/custom_tracker/entry.rb', line 51 def to_s <<~HEREDOC Entry #{@id} from #{@time}. Data: #{@data} HEREDOC end |