Class: Marty::Tag

Inherits:
Base show all
Defined in:
app/models/marty/tag.rb

Constant Summary

Constants inherited from Base

Base::COUNT_SIG, Base::DISTINCT_SIG, Base::FIRST_SIG, Base::GROUP_SIG, Base::JOINS_SIG, Base::LAST_SIG, Base::LIMIT_SIG, Base::MCFLY_PT_SIG, Base::NOT_SIG, Base::ORDER_SIG, Base::PLUCK_SIG, Base::SELECT_SIG, Base::WHERE_SIG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

mcfly_pt

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Method Details

.do_create(dt, comment) ⇒ Object



26
27
28
29
30
31
32
# File 'app/models/marty/tag.rb', line 26

def self.do_create(dt, comment)
  o            = new
  o.comment    = comment
  o.created_dt = dt
  o.save!
  o
end

.make_name(dt) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'app/models/marty/tag.rb', line 9

def self.make_name(dt)
  return 'DEV' if Mcfly.is_infinity(dt)

  # If no dt is provided (which is the usual non-testing case), we
  # use Time.now.strftime to name the posting.  This has the effect
  # of using the host's timezone. i.e. since we're in PST8PDT, names
  # will be based off of the Pacific TZ.
  dt ||= Time.now
  dt.strftime('%Y%m%d-%H%M')
end

.map_to_tag(tag_id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/marty/tag.rb', line 38

def self.map_to_tag(tag_id)
  # FIXME: this is really hacky. This function should not take so
  # many different types of arguments.

  case tag_id
  when Integer, /\A[0-9]+\z/
    tag = find_by_id(tag_id)
  when String
    tag = find_by_name(tag_id)
    # if tag name wasn't found, look for a matching
    # posting, then find the tag whose created_dt <= posting dt.
    if !tag
      posting = Marty::Posting.lookup(tag_id)
      tag = find_match(Mcfly.normalize_infinity(posting.created_dt)) if
        posting
    end
  when nil
    tag = get_latest1
  else
    tag = tag_id
  end

  raise "bad tag identifier #{tag_id.inspect}" unless tag.is_a? Marty::Tag
  tag
end

Instance Method Details

#isdev?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/marty/tag.rb', line 34

def isdev?
  Mcfly.is_infinity(created_dt)
end

#set_tag_nameObject



21
22
23
24
# File 'app/models/marty/tag.rb', line 21

def set_tag_name
  self.name = self.class.make_name(self.created_dt)
  true
end