Class: Ronn::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/ronn/index.rb

Overview

An individual index reference. A reference can point to one of a few types of locations:

- URLs: "http://man.cx/crontab(5)"
- Relative paths to ronn manuals: "crontab.5.ronn"

The #url method should be used to obtain the href value for HTML.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, name, location) ⇒ Reference

Returns a new instance of Reference.



146
147
148
149
150
# File 'lib/ronn/index.rb', line 146

def initialize(index, name, location)
  @index = index
  @name = name
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



144
145
146
# File 'lib/ronn/index.rb', line 144

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



144
145
146
# File 'lib/ronn/index.rb', line 144

def name
  @name
end

Instance Method Details

#manual?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/ronn/index.rb', line 152

def manual?
  name =~ /\([0-9]\w*\)$/
end

#pathObject



176
177
178
# File 'lib/ronn/index.rb', line 176

def path
  File.expand_path(location, File.dirname(@index.path)) if relative?
end

#relative?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/ronn/index.rb', line 164

def relative?
  !remote?
end

#remote?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/ronn/index.rb', line 160

def remote?
  location =~ /^(?:https?|mailto):/
end

#ronn?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/ronn/index.rb', line 156

def ronn?
  location =~ /\.ronn?$/
end

#urlObject



168
169
170
171
172
173
174
# File 'lib/ronn/index.rb', line 168

def url
  if remote?
    location
  else
    location.chomp('.ronn') + '.html'
  end
end