Sha256: 8dae05fa7b19055309d8e66c6feb62dca77514293ce41f5a8ce8b7587e47c411

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

# Microformat

Reads Microformats from HTML documents

## Installation

Add this line to your application's Gemfile:

```ruby
gem "microformat"
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install microformat

## Usage

You can parse a document (or partial document), providing the HTML as a string:

```ruby
html = "<html>...</html>"
Microformat.parse(html) # => Microformat::Collection
```

Or provide a Nokogiri element:

```ruby
require "nokogiri"

html = "<html>...</html>"
doc = Nokogiri::HTML(html)
element = doc.css(".hreview")
Microformat.parse(element)
# => Microformat::Collection
```

Collections act as standard Ruby arrays, however they provide additional filtering methods:

```ruby
collection = Microformat.parse(element)
# => Microformat::Collection (of all microformat objects)
collection.filter(Microformat::Review, Microformat::ReviewAggregate)
# => Microformat::Collection (of only hreviews and hreview-aggregates)
```

You can also improve performance by passing a set of formats to the initial parse:

```ruby
formats = [Microformat::Review, Microformat::Card]
Microformat.parse(element, filter: formats)
# => Microformat::Collection (of only hreviews and hcards)
```

You can specify a limit (should you only want the first or a few objects)

```ruby
Microformat.parse(element, limit: 3)
# => Microformat::Collection (of max size 3)
```

You can also parse a Nokogiri element to return an object of the first found exact Microformat:

```ruby
html = "<html>...</html>"
doc = Nokogiri::HTML(html)
element = doc.css(".hcard")
Microformat::Card.parse(element)
# => Microformat::Card instance
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
microformat-0.0.2 README.md