Microformats (ruby)

Build Status Code Climate

A Ruby gem to parse HTML containing one or more microformats and microformats2 and return a collection of dynamically defined Ruby objects, a Ruby hash or a JSON hash.

Development Status

Implemented:

Not Implemented:

Current Version

4.0.3

Version 4.0.3

Requirements

Installation

Add this line to your application’s Gemfile:

ruby gem "microformats"

And then execute:

bundle

Or install it yourself as:

gem install microformats

Usage

```ruby require “microformats”

source = “<div class='h-card'><p class='p-name'>Jessica Lynn Suttles</p></div>” collection = Microformats.parse(source)

getting a copy of the canonical microformats hash structure

collection.to_hash

the above, as JSON in a string

collection.to_json

shortcuts

return a string if there is only one item found

collection.card.name #=> “Jessica Lynn Suttles”

source = “<article class='h-entry'>

Microformats 2

Jessica Lynn Suttles

</article>” collection = Microformats.parse(source) collection.entry.name.to_s #=> “Microformats 2”

accessing nested microformats

collection.entry.author.name.to_s #=> “Jessica Lynn Suttles”

accessing nested microformats can use shortcuts or more expanded method

collection.entry.author.name #=> “Jessica Lynn Suttles” collection.entry.properties.author.properties.name.to_s #=> “Jessica Lynn Suttles”

use _ instead of - to get these items

collection.entry.author.first_name #=> “Jessica” collection.rel_urls #=> {}

source = “<article class='h-entry'>

Microformats 2

Jessica Lynn Suttles

Brandon Edens

</article>” collection = Microformats.parse(source)

arrays of items with always take the first item by default

collection.entry.author.name #=> “Jessica Lynn Suttles” collection.entry.author(1).name #=> “Brandon Edens”

get the actual array with :all

collection.entry.author(:all).count #=> 2 collection.entry.author(:all)[1].name #=> “Brandon Edens”

```

  • source can be a URL, filepath, or HTML

Console utility

This gem also provides a command like script ‘microformats’ that will return the JSON equivalent microformats http://example.com

You can give the microformats script a URL, filepath, or HTML

additionally, the script will accept input piped from stdin

curl http://example.com | microformats

Ruby Gem release process

Check out latest code from GitHub repo.

git pull origin master

Make sure the version has been bumped up in all four places:

Do a test build locally to make sure it builds properly.

rake build

If that works, then do a test install locally.

rake install

If that works, uninstall the gem.

gem uninstall microformats

Clean up any mess made from testing.

rake clean rake clobber

Assuming your one of the gem owners and have release privileges, release the gem!

rake release

If that works, you’ve just release a new version of the gem! Yay! You can see it at:

https://rubygems.org/gems/microformats

If rake release failed because of an error with your authentication to rubygems.org, follow their instructions in the error message. Then repeat the rake release step.

If any other errors failed along the way before rake release, try to figure them out or reach out to the IRC/Slack channel for help.

Good luck.

Authors

Contributions

  1. Fork it
  2. Get it running (see Installation above)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Write your code and specs
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

If you find bugs, have feature requests or questions, please file an issue.

Testing

Specs

This uses a copy of microformats tests repo.

To run specs ``` rake spec

Interactive

You can use the code interacively for testing but running bundle console

License

Microformats (ruby) is dedicated to the public domain using Creative Commons – CC0 1.0 Universal.

http://creativecommons.org/publicdomain/zero/1.0