Module: PHPF

Defined in:
lib/phpf/constants.rb,
lib/phpf/evaluation.rb,
lib/phpf/tokenizing.rb,
lib/phpf/translations.rb

Constant Summary collapse

RFC850 =

cf. php.net/manual/en/class.datetime.php#datetime.constants.types

DATE_RFC822/DATE_COOKIE/DATE_RFC1123/DATE_RSS, DATE_ISO8601, and DATE_RFC2822 all have equivalent Ruby methods.

"l, d-M-y H:i:s T".freeze
RFC1036 =
"D, d M y H:i:s O".freeze
FormatCharacters =
'dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU'

Class Method Summary collapse

Class Method Details

.evaluate(tokens, time) ⇒ Object



2
3
4
5
6
# File 'lib/phpf/evaluation.rb', line 2

def self.evaluate(tokens, time)
  tokens.map do |token|
    translations.has_key?(token) ? call(translations[token], time) : token
  end
end

.tokenize(format_string) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/phpf/tokenizing.rb', line 4

def self.tokenize(format_string)
  tokens = []
  until format_string.empty?
    case format_string
      when /^([#{FormatCharacters}])/
        tokens << $1.to_sym
      when /^\\([#{FormatCharacters}])/
        tokens << $1
      when /^([^\\#{FormatCharacters}]+?)(?=[\\#{FormatCharacters}])/
        tokens << $1
      when /^([^\\#{FormatCharacters}]+?)$/
        tokens << $1
      else
        raise 'cannot tokenize format string: %p' % format_string
    end
    format_string = $'
  end
  return tokens
end

.untokenize(tokens) ⇒ Object



24
25
26
# File 'lib/phpf/tokenizing.rb', line 24

def self.untokenize(tokens)
  tokens.map { |token| untok(token, token.to_s) }.join
end