Class: MyPrecious::MarkdownAdapter
- Inherits:
-
Object
- Object
- MyPrecious::MarkdownAdapter
- Defined in:
- lib/myprecious.rb
Overview
Dependency info wrapper to generate nice Markdown columns
This wrapper takes basic data from the underlying dependency info object and returns enhanced Markdown for selected columns (e.g. name
).
Instance Attribute Summary collapse
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
Instance Method Summary collapse
-
#changelog ⇒ Object
Render short links for http: or https: changelog URLs.
-
#color ⇒ Object
Get a CSS-style hex color code corresponding to the obsolescence of the dependency.
-
#color_swatch ⇒ Object
Markdown for an obsolescence color swatch.
-
#initialize(dep) ⇒ MarkdownAdapter
constructor
A new instance of MarkdownAdapter.
-
#license ⇒ Object
Include update info in the license column.
-
#method_missing(meth, *args, &blk) ⇒ Object
Delegate other attribute queries to the base dependency object.
-
#name ⇒ Object
Generate Markdown linking the
name
to the homepage for the dependency. - #obsolescence ⇒ Object
-
#recommended_version ⇒ Object
Include information about temporal difference between current and recommended versions.
Constructor Details
#initialize(dep) ⇒ MarkdownAdapter
Returns a new instance of MarkdownAdapter.
425 426 427 428 |
# File 'lib/myprecious.rb', line 425 def initialize(dep) super() @dependency = dep end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
Delegate other attribute queries to the base dependency object
Errors are caught and rendered as “(error)”
533 534 535 536 537 538 539 |
# File 'lib/myprecious.rb', line 533 def method_missing(meth, *args, &blk) dependency.send(meth, *args, &blk) rescue NoMethodError raise rescue StandardError "(error)" end |
Instance Attribute Details
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
429 430 431 |
# File 'lib/myprecious.rb', line 429 def dependency @dependency end |
Instance Method Details
#changelog ⇒ Object
Render short links for http: or https: changelog URLs
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/myprecious.rb', line 484 def changelog base_val = begin dependency.changelog rescue StandardError return "(error)" end begin uri = URI.parse(base_val) if ['http', 'https'].include?(uri.scheme) return "[on #{uri.hostname}](#{base_val})" end rescue StandardError end return base_val end |
#color ⇒ Object
Get a CSS-style hex color code corresponding to the obsolescence of the dependency
510 511 512 513 514 515 516 517 |
# File 'lib/myprecious.rb', line 510 def color case dependency.obsolescence when :mild then "dde418" when :moderate then "f9b733" when :severe then "fb0e0e" else "4dda1b" end end |
#color_swatch ⇒ Object
Markdown for an obsolescence color swatch
Sourced from: stackoverflow.com/a/41247934
524 525 526 |
# File 'lib/myprecious.rb', line 524 def color_swatch "" end |
#license ⇒ Object
Include update info in the license column
470 471 472 473 474 475 476 477 478 479 |
# File 'lib/myprecious.rb', line 470 def license value = dependency.license if value.update_info "#{value}<br/>(#{value.update_info})" else value end rescue StandardError "(error)" end |
#name ⇒ Object
Generate Markdown linking the name
to the homepage for the dependency
434 435 436 437 438 439 440 441 442 443 |
# File 'lib/myprecious.rb', line 434 def name cswatch = begin color_swatch + ' ' rescue StandardError '' end "#{cswatch}[#{dependency.name}](#{dependency.homepage_uri})" rescue StandardError dependency.name end |
#obsolescence ⇒ Object
501 502 503 504 505 |
# File 'lib/myprecious.rb', line 501 def obsolescence color_swatch rescue StandardError '' end |
#recommended_version ⇒ Object
Include information about temporal difference between current and recommended versions
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/myprecious.rb', line 449 def recommended_version recommended_version = dependency.recommended_version if dependency.current_version < recommended_version span_comment = begin if days_newer = dependency.days_between_current_and_recommended " -- #{days_newer} days newer" else "" end end "**#{recommended_version}**#{span_comment}" else recommended_version end rescue StandardError recommended_version || "(error)" end |