Skip to content

Commit f25f3fd

Browse files
author
Kelley Reynolds
committed
Update the README
1 parent 74079f6 commit f25f3fd

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

ruby/README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ This is the Ruby implementation of [referer-parser] [referer-parser], the librar
44

55
The implementation uses the shared 'database' of known referers found in [`referers.yml`] [referers-yml].
66

7-
**Currently the Ruby library only extracts search engine referers - it needs updating with the additional functionality now found in the Java/Scala version.**
8-
97
## Installation
108

119
Add this line to your application's Gemfile:
@@ -22,20 +20,51 @@ Or install it yourself as:
2220

2321
## Usage
2422

25-
Use referer-parser like this:
23+
### To include referer-parser:
2624

2725
```ruby
2826
require 'referer-parser'
27+
```
28+
29+
### To create a parser
30+
31+
Parsers are created by default with the set of included referers but they can also be loaded from another file(s) either during or after instantiation
32+
33+
Creating and modifying the parser:
34+
35+
```ruby
36+
# Default parser
37+
parser = RefererParser::Parser.new
2938

30-
referer_url = 'http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari'
39+
# Custom parser with local file
40+
parser = RefererParser::Parser.new('/path/to/other/referers.yml')
3141

32-
r = RefererParser::Referer.new(referer_url)
42+
# From a URI
43+
parser = RefererParser::Parser.new('http://example.com/path/to/other/referers.yml')
3344

34-
puts r.known? # => true
35-
puts r.referer # => 'Google'
36-
puts r.search_parameter # => 'q'
37-
puts r.search_term # => 'gateway oracle cards denise linn'
38-
puts r.uri.host # => 'www.google.com'
45+
# Default referers, then merge in a set of custom internal domains
46+
parser = RefererParser::Parser.new
47+
parser.update('/path/to/internal.yml')
48+
49+
# Clear all of the existing referers
50+
parser.clear!
51+
```
52+
53+
### Using a parser
54+
55+
The parser returns a hash of matching data if it can be found including search terms, medium, and nicely-formatted source name.
56+
If there is no match, :known will be false.
57+
58+
```ruby
59+
parser = RefererParser::Parser.new
60+
parser.parse('http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari')
61+
# => {
62+
:known=>true,
63+
:uri=>"http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari",
64+
:source=>"Google",
65+
:medium=>"search",
66+
:term=>"gateway oracle cards denise linn"
67+
}
3968
```
4069

4170
## Contributing

0 commit comments

Comments
 (0)