Class: RMQFont

Inherits:
Object show all
Defined in:
lib/project/ruby_motion_query/rmq_font.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, font_family, size, text_style) ⇒ RMQFont



14
15
16
17
18
19
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 14

def initialize(name, font_family, size, text_style)
  @name = name
  @font_family = font_family
  @text_style = text_style
  @size = size
end

Instance Attribute Details

#font_familyObject

Returns the value of attribute font_family.



12
13
14
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 12

def font_family
  @font_family
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 12

def name
  @name
end

#sizeObject

Returns the value of attribute size.



12
13
14
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 12

def size
  @size
end

#text_styleObject

Returns the value of attribute text_style.



12
13
14
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 12

def text_style
  @text_style
end

Class Method Details

.add_named(name, font_family, size, text_style) ⇒ Object



47
48
49
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 47

def add_named(name, font_family, size, text_style)
  font_cache[name] = RMQFont.new(name, font_family, size, text_style)
end

.font_cacheObject



56
57
58
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 56

def font_cache
  @font_cache ||= {}
end

.method_missing(font_key) ⇒ Object



51
52
53
54
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 51

def method_missing(font_key)
  # define_singleton_method isn't implemented in Android :'(
  font_cache[font_key]
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 21

def inspect
  "<RMQFont #{@name} \"#{@font_family}\" #{@size} #{@text_style}>"
end

#sdk_text_styleObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 29

def sdk_text_style
  case @text_style
  when :bold
    Android::Graphics::Typeface::BOLD
  when :italic
    Android::Graphics::Typeface::ITALIC
  when :bold_italic
    Android::Graphics::Typeface::BOLD_ITALIC
  when :normal
    Android::Graphics::Typeface::NORMAL
  end
end

#to_sObject



25
26
27
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 25

def to_s
  self.inspect
end

#to_typefaceObject



42
43
44
# File 'lib/project/ruby_motion_query/rmq_font.rb', line 42

def to_typeface
  Android::Graphics::Typeface.create(@font_family, sdk_text_style)
end