Class: Typekit::Variation

Inherits:
Object
  • Object
show all
Includes:
MassAssignment
Defined in:
lib/typekit/variation.rb

Overview

TODO:

Move lazy loading into a module

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MassAssignment

#initialize, #mass_assign

Instance Attribute Details

#font_styleObject

Returns the value of attribute font_style.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def font_style
  @font_style
end

#font_variantObject

Returns the value of attribute font_variant.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def font_variant
  @font_variant
end

#font_weightObject

Returns the value of attribute font_weight.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def font_weight
  @font_weight
end

#foundryObject

Returns the value of attribute foundry.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def foundry
  @foundry
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def id
  @id
end

#librariesObject

Returns the value of attribute libraries.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def libraries
  @libraries
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def name
  @name
end

#postscript_nameObject

Returns the value of attribute postscript_name.



5
6
7
# File 'lib/typekit/variation.rb', line 5

def postscript_name
  @postscript_name
end

Instance Method Details

#fetch(attribute) ⇒ Object Also known as: reload

Note:

This is called lazily when you access any non-loaded attribute and doesn’t need to be called manually unless you want to reload the data. This means we can return an array of Variation objects for Family#variations without making N+1 requests to the API.

Get detailed information about this Family Variation from Typekit

Parameters:

  • attribute (Symbol)

    Optionally return a single attribute after data is loaded

Returns:

  • Returns @attribute if attribute argument is specified; otherwise returns self



30
31
32
33
34
# File 'lib/typekit/variation.rb', line 30

def fetch(attribute)
  family_id, variation_id = @id.split(':')
  mass_assign Client.get("/families/#{family_id}/#{variation_id}")
  attribute ? instance_variable_get("@#{attribute}") : self
end

#to_fvdString

Convert the variation name to the Font Variation Description for adding it to a Kit

Returns:

  • (String)

    Font Variation ID (e.g. ‘n4’ or ‘i7’)



39
40
41
# File 'lib/typekit/variation.rb', line 39

def to_fvd
  id.split(':').last
end