Class: CSSPool::Collection
- Inherits:
-
Object
- Object
- CSSPool::Collection
- Includes:
- Enumerable
- Defined in:
- lib/csspool/collection.rb
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #[](idx) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(&block) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
- #length ⇒ Object
Constructor Details
#initialize(&block) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 |
# File 'lib/csspool/collection.rb', line 5 def initialize &block @docs = [] @block = block end |
Instance Method Details
#<<(string) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/csspool/collection.rb', line 10 def << string doc = CSSPool.CSS string import_tree = [[doc]] imported_urls = {} until import_tree.last.all? { |x| x.import_rules.length == 0 } level = import_tree.last import_tree << [] level.each do |l| l.import_rules.each do |ir| next if imported_urls.key? ir.uri new_doc = ir.load(&@block) imported_urls[ir.uri] = ir.load(&@block) import_tree.last << new_doc end end end @docs += import_tree.flatten.reverse self end |
#[](idx) ⇒ Object
40 41 42 |
# File 'lib/csspool/collection.rb', line 40 def [] idx @docs[idx] end |
#each(&block) ⇒ Object
44 45 46 |
# File 'lib/csspool/collection.rb', line 44 def each &block @docs.each(&block) end |
#last ⇒ Object
48 |
# File 'lib/csspool/collection.rb', line 48 def last; @docs.last; end |
#length ⇒ Object
36 37 38 |
# File 'lib/csspool/collection.rb', line 36 def length @docs.length end |