Class: Bike::Meta::Timestamp

Inherits:
Field
  • Object
show all
Includes:
Bike::Meta
Defined in:
lib/meta/timestamp.rb

Constant Summary collapse

REX_DATE =
/\A(\d+).(\d+).(\d+)(?:[T\s](\d+):(\d+)(?::(\d+))?)?\z/

Constants inherited from Field

Field::DEFAULT_META

Instance Attribute Summary

Attributes inherited from Field

#action, #result

Instance Method Summary collapse

Methods included from Bike::Meta

#post

Methods inherited from Field

#[], #[]=, #commit, #create, #default_action, #delete, #empty?, #find_ancestor, #get, h, #inspect, instance, #item, #load, #load_default, #meta_admins, #meta_client, #meta_folder, #meta_full_name, #meta_group, #meta_name, #meta_owner, #meta_owners, #meta_roles, #meta_sd, #meta_short_name, #pending?, #permit?, #post, #update, #val, #valid?, #workflow

Methods included from I18n

_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=

Constructor Details

#initialize(meta = {}) ⇒ Timestamp

Returns a new instance of Timestamp.



14
15
16
17
18
19
# File 'lib/meta/timestamp.rb', line 14

def initialize(meta = {})
  meta[:size]       = $&.to_i if meta[:tokens] && meta[:tokens].find {|t| t =~ /^\d+$/ }
  meta[:can_edit]   = true if Array(meta[:tokens]).include? 'can_edit'
  meta[:can_update] = true if Array(meta[:tokens]).include? 'can_update'
  super
end

Instance Method Details

#errorsObject



21
22
23
24
25
26
27
28
29
# File 'lib/meta/timestamp.rb', line 21

def errors
  if @date_str.nil?
    []
  elsif @date_str =~ REX_DATE
    (Time.local($1, $2, $3, $4, $5, $6) rescue nil) ? [] : ['out of range']
  else
    ['wrong format']
  end
end