package ReaderInfo;

use strict;
use warnings;

use JSON;
use Data::Dumper;

sub new {
	my( $class, $filename ) = @_;

	# Load JSON file
	local $/;
	open( my $fh, '<', $filename );
	my $json_text = <$fh>;
	
	# Decode JSON
	my $self = decode_json( $json_text );
	
	bless( $self, $class );

	return $self;
}

sub get_OS {
	my $self = shift;
	my @os_names;
	my $os;
	
	foreach $os ( @{$self->{'os'}} )
	{
		push( @os_names, $os->{'canonical_name'} );
	}
	return @os_names;
}

sub get_OS_string {
  # String of all supported OSes for display in user interface
  my $self = shift;
  my @os_names;
  
  foreach ( @{$self->{'os'}} ) {
    push( @os_names, $_->{'name'} );
  }
  return join(', ', @os_names);
}

sub get_installer {
  my $self = shift;
  my $os = shift;

  foreach ( @{$self->{'os'}} ) {
    if ( $_->{'canonical_name'} eq $os ) { return $_->{'installer'}; }
  }
  return '';
}

sub get_Browsers {
	my $self = shift;
	my @browser_names;
	my $browser;
	
	foreach $browser ( @{$self->{'browsers'}} )
	{
		push( @browser_names, $browser->{'canonical_name'} );
	}
	return @browser_names;
}

sub get {
  my $self = shift;
  my $name = shift;
  return $self->{$name};
}

1;
