Class: LEWT::LEWTLedger
- Inherits:
-
Hash
- Object
- Hash
- LEWT::LEWTLedger
- Defined in:
- lib/lewt_ledger.rb
Overview
LEWTLedger is a pre-formated hash structure that conforms somewhat to a standard general ledger entry.
Keys
date_start:: Start date the entry occured on
date_end:: End date the entry occured on
category:: Some sort of general category for this entry i.e: 'Hourly Income', 'Operating Expenses' etc.
entity:: The entiry with whom this transaction occured with
description:: A description of the entry
quantity:: How many units
unit_cost:: The cost per unit
sub_total (optional):: A total or defaults to quantity * unit_cost
gst (optional):: The GST (VAT) amount to be added for this entry. Defaults to 0.
total (optional):: The total, including tax, for this entry. Defaults to sub_total + gst
Usage
ledger = LEWTLedger.new(params, ...)
Furthermore LEWTLedger provides some methods to work with metatags. Metatags can be embedded inside your extraction sources. I like to put mine in my ‘description’ fields, it works well with Calender Extractor. The meta data is basically a hash tag, you can do stuff like this:
'#happiness=10/10'
'#ignore-cost'
meta tags that do not assign a value [ie: =something] will evaluate to a boolean true flag. If you assign a value it must be a fraction, this will be evaluated as a ruby Rational type. Your extensions can respond to these tags however they like. The metatags can be accessed with the metatags
reader attribute:
ledger_data.
Constant Summary collapse
- MATCH_SINGLE_META_REGEX =
This is a general matching regex for metatags.
/[#](\S*)/
- MATCH_MULTIPLE_META_REGEX =
/#\S*/
Instance Attribute Summary collapse
-
#metatags ⇒ Object
readonly
Returns the value of attribute metatags.
Instance Method Summary collapse
-
#initialize(args) ⇒ LEWTLedger
constructor
A new instance of LEWTLedger.
-
#parse_meta_tags(field_key) ⇒ Object
parses a field on this object for meta data.
Constructor Details
#initialize(args) ⇒ LEWTLedger
Returns a new instance of LEWTLedger.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lewt_ledger.rb', line 43 def initialize (args) raise ArgumentError, "#{self.class.name} was not instantized with valid parameters" if valid?(args) == false self[:date_start] = args[:date_start] self[:date_end] = args[:date_end] self[:category] = args[:category] self[:entity] = args[:entity] self[:description] = args[:description] self[:quantity] = args[:quantity] self[:unit_cost] = args[:unit_cost] self[:sub_total] = self[:sub_total] || self[:quantity] * self[:unit_cost] self[:gst] = args[:gst] || 0 self[:total] = args[:total] || ( self[:sub_total] + self[:gst] ) @metatags = (:description) if @metatags != nil end |
Instance Attribute Details
#metatags ⇒ Object (readonly)
Returns the value of attribute metatags.
37 38 39 |
# File 'lib/lewt_ledger.rb', line 37 def @metatags end |
Instance Method Details
#parse_meta_tags(field_key) ⇒ Object
parses a field on this object for meta data. Meta data can be embedded inside the ledger fields as a string by prefixing it with the ‘#’ symbol. If you assign a value to the meta field with the ‘=’ symbol, its value will be interpreted as a number. ie:
#good-pay // true
#happiness=6/10 // Rational(6,10)
- field_key [Symbol]
-
the ledger key you wish to parse as a symbol.
66 67 68 69 70 |
# File 'lib/lewt_ledger.rb', line 66 def ( field_key ) value = self[field_key] = value return end |