Class: Typekit::Family

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MassAssignment

#initialize, #mass_assign

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/typekit/family.rb', line 4

def description
  @description
end

#foundryObject

Returns the value of attribute foundry.



4
5
6
# File 'lib/typekit/family.rb', line 4

def foundry
  @foundry
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/typekit/family.rb', line 4

def id
  @id
end

#librariesObject

Returns the value of attribute libraries.



4
5
6
# File 'lib/typekit/family.rb', line 4

def libraries
  @libraries
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/typekit/family.rb', line 4

def name
  @name
end

#slugObject

Returns the value of attribute slug.



4
5
6
# File 'lib/typekit/family.rb', line 4

def slug
  @slug
end

#variationsObject

Returns the value of attribute variations.



4
5
6
# File 'lib/typekit/family.rb', line 4

def variations
  @variations
end

Returns the value of attribute web_link.



4
5
6
# File 'lib/typekit/family.rb', line 4

def web_link
  @web_link
end

Class Method Details

.find(id) ⇒ Object

Retrieve a specific Family

Parameters:

  • id (String)

    The Typekit Family id (e.g. ‘brwr’ or ‘gkmg’)



17
18
19
20
21
# File 'lib/typekit/family.rb', line 17

def find(id)
  family = Family.new Client.get("/families/#{id}")
  family.variations.map! { |v| Variation.send(:new, v) }
  family
end

.find_by_name(name) ⇒ Object

Retrieve a Family by font family name

Parameters:

  • name (String)

    The name of the font family without variation (e.g. ‘FF Meta Web Pro’ or ‘Droid Sans’)



32
33
34
# File 'lib/typekit/family.rb', line 32

def find_by_name(name)
  find_by_slug name.downcase.gsub(/[^a-z]+/, '-')
end

.find_by_slug(slug) ⇒ Object

TODO:

Add error handling

Retrieve a Family by Typekit slug

Parameters:

  • slug (String)

    The Typekit Family slug for the font family (e.g. ‘ff-meta-web-pro’ or ‘droid-sans’)



26
27
28
# File 'lib/typekit/family.rb', line 26

def find_by_slug(slug)
  find(Client.get("/families/#{slug}")['id'])
end

Instance Method Details

#variation(id) ⇒ Object

Find a variation in this Family by the Font Variation Description

Parameters:

  • id (String)

    Family/Font variation ID/Description (e.g. n4 or i7)



10
11
12
# File 'lib/typekit/family.rb', line 10

def variation(id)
  variations.select { |v| v.id.split(':').last == id }.first
end