Class: YTag::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/ytag/tag.rb

Constant Summary collapse

MARKUP =
{}
BOGUS =
'system:undefined'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, user, active = true, hidden = false) ⇒ Tag

Returns a new instance of Tag.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ytag/tag.rb', line 18

def initialize(name, user, active=true, hidden=false)
  raise ArgumentError, 'nil name' if name.nil?
  raise ArgumentError, 'invalid name class' if name.class != String
  raise ArgumentError, 'empty name' if name.empty?
  raise ArgumentError, 'nil user' if user.nil?
  raise ArgumentError, 'invalid user class' if user.class != String
  raise ArgumentError, 'empty user' if user.empty?
  raise ArgumentError, 'invalid active class' if \
    active.class != TrueClass && active.class != FalseClass
  raise ArgumentError, 'invalid hidden class' if \
    hidden.class != TrueClass && hidden.class != FalseClass

  @name = YTag::tagify(name)
  @user = user
  @active = active
  @hidden = hidden
  @timestamp = RCL::Timestamp.new

  nil
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



13
14
15
# File 'lib/ytag/tag.rb', line 13

def active
  @active
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



13
14
15
# File 'lib/ytag/tag.rb', line 13

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/ytag/tag.rb', line 13

def name
  @name
end

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'lib/ytag/tag.rb', line 13

def user
  @user
end

Instance Method Details

#accessObject



47
48
49
# File 'lib/ytag/tag.rb', line 47

def access
  @timestamp.access
end

#createObject



39
40
41
# File 'lib/ytag/tag.rb', line 39

def create
  @timestamp.create
end

#modifyObject



43
44
45
# File 'lib/ytag/tag.rb', line 43

def modify
  @timestamp.modify
end


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ytag/tag.rb', line 51

def print(stream=STDOUT)
  raise 'nil stream' if stream.nil?
  raise 'invalid stream class' if stream.class != IO

  @timestamp.update_access

  stream << "#{@name} ["
  stream << 'in' if !@active
  stream << 'active, '
  if !@hidden
    stream << 'public'
  else
    stream << 'private'
  end
  stream << "]\n"

  stream << "+ added by #{@user} on #{@timestamp.create}\n"
  stream << "+ last accessed on #{@timestamp.access}\n"

  nil
end