Class: PFA::NTime

Inherits:
Object
  • Object
show all
Defined in:
lib/pfa/node_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(foo, zero_offset = 0) ⇒ NTime

On peut initialiser un NTime avec :

- [Integer]     Des secondes
- [Time]        Un temps
- [String]      Une horloge
- [PFA::NTime]  Une instance PFA::NTime (comme celle-ci)

Parameters:

  • \Integer

    zero_offset Décalage du temps avec zéro



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pfa/node_time.rb', line 24

def initialize(foo, zero_offset = 0)
  @zero_offset = zero_offset
  case foo
  when Integer    then @secondes = foo
  when Float      then @secondes = foo.to_i
  when PFA::NTime then @secondes = foo.to_i
  when Time       then @secondes = foo.to_i
  when String     then @secondes = PFA.h2s(foo)
  else raise PFAFatalError.new(53, {value: "#{foo}", classe:"#{foo.class}"})  
  end
  @secondes -= zero_offset
end

Instance Attribute Details

#secondesObject (readonly)

Integer Nombre de secondes pour ce temps



11
12
13
# File 'lib/pfa/node_time.rb', line 11

def secondes
  @secondes
end

#zero_offsetObject (readonly)

Integer Nombre de secondes du zéro



14
15
16
# File 'lib/pfa/node_time.rb', line 14

def zero_offset
  @zero_offset
end

Instance Method Details

#+(secs) ⇒ Object

Addition

Parameters:

  • secondes

    PFA::NTime ou Integer



169
170
171
172
# File 'lib/pfa/node_time.rb', line 169

def +(secs)
  secs = secs.to_i if secs.is_a?(PFA::NTime)
  return PFA::NTime.new(secs + @secondes)
end

#-(secs) ⇒ Object



174
175
176
177
# File 'lib/pfa/node_time.rb', line 174

def -(secs)
  secs = secs.to_i if secs.is_a?(PFA::NTime)
  return PFA::NTime.new(@secondes - secs)
end

#<(nodetime) ⇒ Object



179
180
181
# File 'lib/pfa/node_time.rb', line 179

def <(nodetime)
  @secondes < nodetime.to_i
end

#>(nodetime) ⇒ Object



183
184
185
# File 'lib/pfa/node_time.rb', line 183

def >(nodetime)
  @secondes > nodetime.to_i
end

#as_dureeObject



43
44
45
# File 'lib/pfa/node_time.rb', line 43

def as_duree
  @as_duree ||= PFA.s2h(secondes, **{as: :duree})
end

#as_horlogeObject Also known as: to_horloge



38
39
40
# File 'lib/pfa/node_time.rb', line 38

def as_horloge
  @to_horloge ||= PFA.s2h(secondes)
end

#as_horloge_with_offset(abs_time) ⇒ String

la valeur idéale (seulement pour les noeuds relatifs) si ce décalage existe.

Parameters:

Returns:

  • (String)

    Une horloge qui indique le décalage avec



61
62
63
64
65
66
67
68
69
70
# File 'lib/pfa/node_time.rb', line 61

def as_horloge_with_offset(abs_time)
  @as_horloge_with_offset ||= begin
    if offset?
      signe   = self > abs_time ? '+' : '-'
      "#{self.as_horloge} (#{signe}#{offset.as_duree})" 
    else
      self.as_horloge
    end
  end
end

#as_img_horloge_code(node, **options) ⇒ Object

image avec ImageMagick pour le noeud node

Parameters:

  • node (PFA::RelativePFA::Node)

    Le nœud de l’horloge

  • options (Hash)

    Plus tard, pourra redéfinir :bg_color et :color



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/pfa/node_time.rb', line 139

def as_img_horloge_code(node, **options)
  for_real = options[:pfa_type] == :real
  <<~CMD.strip
  \\(
  -background #{options[:bg_color]||'transparent'}
  -stroke #{options[:color]||'gray20'}
  -fill #{options[:color]||'gray20'}
  -strokewidth 1
  -pointsize #{MagickPFA::BASE_FONTSIZE * MagickPFA::HORLOGE_FONT_SIZES[node.type]}
  -size #{surface}
  -gravity #{options[:gravity]||'Center'}
  label:"#{for_real ? self.as_horloge_with_offset(options[:abs_time]) : as_horloge}"
  -extent #{surface}
  \\)
  -gravity northwest
  -geometry +#{node.send(for_real ? :left : :abs_left) + 24}+#{node.send(for_real ? :top : :abs_top) + 8}
  -composite
  CMD
end

#background_per_offsetObject



90
91
92
93
94
95
96
97
98
# File 'lib/pfa/node_time.rb', line 90

def background_per_offset
  @background_per_offset ||= begin
    if offset > 120
      'gray40' # offset trop grand
    else
      'transparent'
    end
  end
end

#calc_offset(abs_time) ⇒ Object

– Méthodes de décalage –



49
50
51
52
53
# File 'lib/pfa/node_time.rb', line 49

def calc_offset(abs_time)
  offset_secondes = (abs_time.to_i - self.to_i).abs
  @offset     = self.class.new(offset_secondes)
  @hasoffset  = offset > 30
end

#foreground_per_offsetObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pfa/node_time.rb', line 99

def foreground_per_offset
  @foreground_per_offset ||= begin
    if offset < 60
      'gray60'
    elsif offset < 120
      'gray20'
    else
      'white'
    end
  end
end

#offsetObject

PFA::NTime

Décalage entre le temps absolu et le temps réel



112
113
114
# File 'lib/pfa/node_time.rb', line 112

def offset
  @offset
end

#offset?Boolean

temps absolu

Returns:

  • (Boolean)

    true s’il y a un décalage trop important avec le



75
76
77
# File 'lib/pfa/node_time.rb', line 75

def offset?
  @hasoffset === true
end

#offset_as_horloge(abs_time) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/pfa/node_time.rb', line 79

def offset_as_horloge(abs_time)
  @offset_as_horloge ||= begin
    if @hasoffset
      signe   = self > abs_time ? '+' : '-'
      " (#{signe}#{offset.as_duree})" 
    else
      " "
    end
  end
end

#relativeObject

PFA::NTime

Le temps relatif (à l’écran)



126
127
128
# File 'lib/pfa/node_time.rb', line 126

def relative
  @relative ||= NTime.new(secondes + zero_offset, 0)
end

#surfaceObject



159
160
161
# File 'lib/pfa/node_time.rb', line 159

def surface
  @surface ||= "#{MagickPFA::PFA_WIDTH/10}x50"
end

#to_iObject



116
117
118
# File 'lib/pfa/node_time.rb', line 116

def to_i
  @secondes
end

#to_px(pfa) ⇒ Object

Retourne la valeur en pixels pour le temps courant (ou la durée)



121
122
123
# File 'lib/pfa/node_time.rb', line 121

def to_px(pfa)
  (self.to_i * pfa.img_builder.coef_pixels).to_i
end