Class: RVGP::Journal::Posting::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/journal/posting.rb

Overview

This class represents a key, or key/value tag, within a journal. These tags can be affixed to transfers and postings. And, are pretty simple, comprising of a key and optionally, a value.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value = nil) ⇒ Tag

Create a tag from it’s constituent parts

Parameters:



64
65
66
67
# File 'lib/rvgp/journal/posting.rb', line 64

def initialize(key, value = nil)
  @key = key
  @value = value
end

Instance Attribute Details

#keyString (readonly)

The label of this tag

Returns:

  • (String)

    the current value of key



58
59
60
# File 'lib/rvgp/journal/posting.rb', line 58

def key
  @key
end

#valueString (readonly)

The value of this tag

Returns:

  • (String)

    the current value of value



58
59
60
# File 'lib/rvgp/journal/posting.rb', line 58

def value
  @value
end

Class Method Details

.from_s(str) ⇒ Tag

Parse the provided string, into a Tag object

Parameters:

  • str (String)

    The tag, possibly a key/value pair, as would be found in a pta journal

Returns:

  • (Tag)

    A parsed representation of this tag



78
79
80
# File 'lib/rvgp/journal/posting.rb', line 78

def self.from_s(str)
  /\A(.+) *: *(.+)\Z/.match(str) ? Tag.new(::Regexp.last_match(1), ::Regexp.last_match(2)) : Tag.new(str)
end

Instance Method Details

#to_sString

Serialize this tag, to a string

Returns:

  • (String)

    the tag, as would be found in a pta journal



71
72
73
# File 'lib/rvgp/journal/posting.rb', line 71

def to_s
  value ? [key, value].join(': ') : key
end